#php

Artisan Error: Failed to listen on localhost:8000

by

I was creating an admin dashboard based on Laravel. UI components were reactive and build upon the vuejs framework. I will have a post on my experience with the vuejs framework someday.

I was switching between a compilation of Vue component changes and running the laravel localhost server. A regular serve command to start localhost:


php artisan serve —host 192.168.10.203 —port 8000

I was serving at the IP address of the machine so I could test conveniently from other machines and devices connected to LAN.

Between development precess somehow the laravel artisan process mustn’t have closed properly. When I attempted to serve localhost I received this error:


Failed to listen on localhost:8000(reason: Address already in use)

CONTINUE READING

How To Optimize Laravel Code Eloquently With UpdateOrCreate()

by

In beginning of my Laravel learning, I did write more lines of code to perform my task than I write now. I started learning to adopt more eloquent ways of coding for Laravel encourages us to write. One simple task I performed by writing this many number of lines:


$place = PlaceModel::where('id', "132")->first();
if(isset($place))
{
  $place->update(['name' => 'Place Name', 'address' => 'Place Address',]);
}
else
{
  $place = PlaceModel::create([
    'name' => 'Place Name',
    'address' => 'Place Address',
  ]);
}

This many lines of code can be optimised to single statement of line in Laravel Eloquent way. This is ome of the ways to optimize eloquent query on Laravel:

CONTINUE READING

Password Laravel Personal/Password Access Client Not Found

by

We must have stumbled on Laravel’s passport sometime for creating authentication api’s for our mobile apps providing full OAuth2 server implementation.

This post uses Laravel 7.x. Our passport installation is


composer require laravel/passport “~9.0”

We will perform the migration where Passport migrations will create the tables our application needs to store clients and access tokens. It will also create Users table for us.


php artisan migrate

We also updated the driver to use passport in config/auth.php


‘api’ => [
            ‘driver’ => ‘passport’,
            ‘provider’ => ‘users’,
            ‘hash’ => false,
        ],

Now in our registration api example when we try to generate access token


$user->createToken(‘MyApp Password Grant Client’)->accessToken;

It gives error:


Auth driver [passport] for guard [api] is not defined.
Personal access client not found.

CONTINUE READING

Recommended posts