jeudi 1 août 2019

how to add Laravel prefix admin and user in dynamic route?

I dont know how to add prefix admin and user role in this dynamic routes laravel. Can anybody help me?

    this is code dynamic routes i have, so how to separate admin and user role?
    plz teach me



via Chebli Mohamed

UnauthorizedHttpException throws even after token send from header

I am using laravel-jwt for authentication. When I send token from header it throws UnauthorizedHttpException. This is working fine on local environment as well as on another server.

Is there any configuration needs on server?

I am sending token through header as, Authorization : Bearer



via Chebli Mohamed

Trying to get property of non-object error in hosting, but in local is not error

I'm trying to show my product history like this one in my localhost screenshot in localhost

but when i tried in hosting ended up with an error like this screenshot in hosting

this is my model code

    <?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Transaction extends Model
{
    protected $table = 'transactions';

    public function User(){
      return $this->belongsTo('App\User');
    }

    public function Product(){
      return $this->belongsTo('App\Product');
    }
}

this is my Controller code

        <?php

    namespace App\Http\Controllers;

    use Illuminate\Http\Request;

    use App\Http\Requests;
    use App\Transaction;
    use App\Cart;
    use App\Product;
    use Auth;
    class TransactionController extends Controller
    {
        public function index(){

          $userTransaction = Transaction::where('user_id',Auth::user()->id)->get();
          $userTransactiondate = Transaction::select('created_at')->where('user_id',Auth::user()->id)->first();
          $getpayment = Transaction::select('payment')->where('user_id',Auth::user()->id)->first();

          return view('transaction.history',compact('userTransaction','userTransactiondate','getpayment'));
        }
    }

this is the view code that error

                @foreach ($userTransaction as $u)

                  <tr>
                  <td ><img src="" width="100" height="100" alt=""></td>
                  <td><br></td>
                  <td style="padding-top:30px;"></td>
                  <td> <br>X</td> 
                  <td style="padding-top:30px;"></td>
                  <td><br>=</td>
                  <td style="padding-top:30px;"></td>
                  </tr>
                @endforeach

            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
@endsection

how am i supposed to do with this error? the code is same in localhost and in hosting, thank you



via Chebli Mohamed

Problem in uploading file in Folder in laravel 5.3?

I am trying to upload image in laravel but i am getting error when I am uploading image in folder, When I am uploading image and clicking on submit button, it's giving me problem in uploading file, i think there are error in this line...

 move_uploaded_file($imageName, $moveable_file);

here are my usercontrolle.php file

public function dropzone(Request $request)
{
    $user = Auth::user()->toArray();
    $user_id = $user['id'];
    $type = 'photo';
    $type_id=0;
    $data = $_FILES["image"];

    //dd($data);
    $doc_id = $_POST["doc_id"];
    $doc_name = $_POST["doc_name"];
    if($doc_id)
    {   $img_id=$doc_id;
        $img_name=$doc_name;
        $response = $this->userService->deleteDocument($img_id,$img_name,$user_id,$type,$type_id);
    }
  // $image_array_1 = explode(";", $data);
  // $image_array_2 = explode(",", $image_array_1[1]);
  // $data = base64_decode($image_array_2[1]);

  $storage_path = env('DOCUMENT_STORAGE_PATH');
  $profile_upload_dir = str_replace(["/","\\"], [DIRECTORY_SEPARATOR,DIRECTORY_SEPARATOR], $storage_path); 

    if($type_id != '0'){
        $destination_path = $profile_upload_dir . $user_id ."\\". $type."\\". $type_id;
        $destination_path = str_replace(["/","\\"], [DIRECTORY_SEPARATOR,DIRECTORY_SEPARATOR], $destination_path);   
    }else{
        $destination_path = $profile_upload_dir . $user_id ."\\". $type;
        $destination_path = str_replace(["/","\\"], [DIRECTORY_SEPARATOR,DIRECTORY_SEPARATOR], $destination_path);   
    }
        if(!is_dir($destination_path)) {
            mkdir($destination_path, 0777,true);
        }
        $imageName = time() . '.png';
       // dd($imageName);
        $moveable_file = str_replace(["/","\\"], [DIRECTORY_SEPARATOR,DIRECTORY_SEPARATOR], $destination_path.'\\'.$imageName); 
        //dd($moveable_file);
        move_uploaded_file($imageName, $moveable_file);
        // file_put_contents($moveable_file, $data);
        //$image_file = addslashes(file_get_contents($moveable_file));
        $user = Auth::user()->toArray();
          //dd($user);
        $user_id = $user['id'];
        $type_id = 0;
        if(isset($photo['type_id']) && !empty($photo['type_id'])){
            $type_id = $photo['type_id'];
        }
        //$photo['file']=$_FILES['photoimg'];
        $photo['type']='photo';
        $result = $this->userService->storeUserDocuments($imageName, $photo['type'], $type_id, $user_id);
        // echo '<img src="data:image/png;base64,'.base64_encode($data).'" data-action="zoom" class="pull-left" style="height: 130px;width:130px;">';

}



via Chebli Mohamed

How to execute a PHP code function concurrently for different processes. Sms scenario

I have been working on a Bulk Sms product and off-late we have been having challenges on the number of sms sent at a time. We have tried several ways to optimize both we have not yet reached a good solution.

Our provider provides provides an endpoint that sends a single SMS at once. We have a function that sends an SMS to that endpoint. Now lets say I have a user who has 10K contacts in a group, and we want to send SMS to that endpoint with the best time as possible.

Is there anyway i can make my code execute the function to concurrently while generating the SMS to my db table?

For example, lets assume the send sms function as sendSms($phone, $message)

Then lets generate the SMS from a group of 10K contacts:

foreach($group->contacts as $contact) {
 //from a controller
 $this->dispatch(new SendSmsJob($contact->phone, $contact->message))->onQueue('high');
}

Clearly the SMS will be created and queued lets say redis, but they are sent sequentially. Is it possible to do a concurrency? Is AWS lambda a solution? or Lavavel Vapor?



via Chebli Mohamed

How to fix "Laravel redirect to the same login page" and middleware return false all time?

Work in server (same code) but in localhost it return false always I have tried many ways.

I have tried Laravel build-in function login and so far the result always return false while debugging.

//Middleware RedirectIfAdmin

namespace App\Http\Middleware;

use Closure; use Illuminate\Support\Facades\Auth;

class RedirectIfAdmin { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param string|null $guard * @return mixed */ public function handle($request, Closure $next, $guard = null) { $auth=Auth::guard('admin'); if (Auth::guard($guard)->check()) {

        return redirect('admin/dashboard');
    }
    return $next($request);
}

}

I will add other code also if needed please tell me I am a new to ask question here. Please guide me.



via Chebli Mohamed

mercredi 31 juillet 2019

How can I change the default message of invalid credentials on OAuthServerException in Laravel Passport?

I am developing an API using Laravel Passport for authentication and my problem is that I cannot change the default message when the login fail due to invalid credentials.

LoginController.php

public function login(Request $request) {
    $this->validate($request, [
        'username' => 'required',
        'password' => 'required'
    ]);

    return $this->issueToken($request, 'password');
}

IssueTokenTrait.php

public function issueToken(Request $request, $grantType, $scope = "") {
    $params = [
        'grant_type' => $grantType,
        'client_id' => $this->client->id,
        'client_secret' => $this->client->secret,
        'scope' => $scope
    ];

    if($grantType !== 'social'){
        $params['username'] = $request->username ?: $request->email;
    }

    $request->request->add($params);
    $proxy = Request::create('oauth/token', 'POST');

    return Route::dispatch($proxy);
}

When I put invalid credentials, it returns:

{
    "error": "invalid_credentials",
    "error_description": "The user credentials were incorrect.",
    "message": "The user credentials were incorrect."
}

I want to change this message because I want the message to depend on the language.



via Chebli Mohamed