Category : laravel-api

I use Laravel 8, and I can’t login in phone.In web it is working correctly. I tried to log user, in web I get the user, but in phone, nothing. Controller if (Auth::attempt($request->only(‘name’, ‘password’), $request->remember)) { return response()->json([‘message’ => true]); } else { return response()->json([‘message’ => false]); } Api Route::get(‘/user’, function (Request $request) { Log::error($request->user()); ..

Read more

I just started yesterday on learning Laravel, whats the better way on calling an API to do CRUD stuffs. (Different controller for API and view) View(request)->controller(call api)->api_controller(return response)->controller(return response)->view (Direct call on the API) (I think this is much simple though I dont know if its the correct way) View(request)->api_controller(return response)->view If both of my ..

Read more

I use laravel 8 & have 3 table: Products, ProductPrice & ProductsPublisher: this is my Products model for this relationship: public function lastPrice(){ return $this->hasMany(ProductPrice::class)->where(‘status’,’active’)->orderBy(‘created_at’,’DESC’)->distinct(‘publisher_id’); } and this is my productsPrice model for publisher relationship: public function getPublisher(){ return $this->belongsTo(ProductsPublisher::class,’publisher_id’); } now, i want to use laravel resource for my api, i wrote products resource: ..

Read more

Actually am trying to create api with Laravel passport, and I have to protect some routes so that only authenticate user can access this routes. Route::post(‘register’, [ApiAuthController::class, ‘register’]); Route::post(‘login’, [ApiAuthController::class, ‘login’]); Route::middleware(‘auth:api’)->group(function () { Route::post(‘/task’, [ApiControllerTaskController::class,’store’]); }); Now here after login I got access token and I used this access token like this. everything is ..

Read more

I want to build a Laravel-API based project where I need User registration, Login, Verify email, Reset password using JWT authentication driver. But I want to use the Laravel build-in functionality of user authentication and registration rather than creating custom login, register functionality. I took the following approach- routes/api.php file <?php use IlluminateHttpRequest; Route::middleware(‘auth:api’)->get(‘/user’, function ..

Read more

I’m trying to work with an API that already given me a TOKEN and I have added this TOKEN at Authorization section as BearerToken and then added this GET request (which requires no parameter): https://seller.digikala.com/api/v1/profile/ But after sending it, I get the Status 401 Unathorized somehow. So what’s going wrong here? How can I properly ..

Read more

I am looking to use Auth::user() in the CompanyController sitting in the api.php route file in Laravel 8. Like Route::get(‘team’, [CompanyController::class, ‘index’]); But if I do so, I won’t be able to access Auth in the following code in the CompanyController file. use IlluminateSupportFacadesAuth; public function index(Request $request) { /** * Role 1 => admin, ..

Read more

Background Let us consider a hypothetical scenario. Suppose we have five different tables in our database, Customers Categories Products Orders OderDetails Our client wants us to add a search bar to the frontend, where a user can search for a specific product and upon tapping the search button, matching products has to be displayed on ..

Read more

My laravel middleware is behaving funny in that anytime I use a middleware, either custom or any default laravel middleware, I get this error Object of class stdClass could not be converted to string and whenever I trace the file the error is coming from, it targets /vendor/laravel/framework/src/Illuminate/Database/Connection.php. please, if you know what could be ..

Read more

I created this api api routes on laravel.. Route::get(‘/items’, [ItemController::class, ‘index’]); Route::prefix(‘/item’, function () { Route::post(‘/store’, [ItemController::class, ‘store’]); Route::put(‘/{id}’, [ItemController::class, ‘update’]); Route::delete(‘/store’, [ItemController::class, ‘destroy’]); when I use GET requests on postman, everything works great but when I use POST requests I get 404 not Found Page! and this is my store function on Item Controller ..

Read more