Set port for php artisan.php serve

Laravel 5.8 to 8.0 and above Simply pass it as a paramter: php artisan serve –port=8080 You may also bind to a specific host by: php artisan serve –host=0.0.0.0 –port=8080 Or (for Laravel 6+) you can provide defaults by setting SERVER_PORT and SERVER_HOST in your .env file. You might need to do php artisan cache: … Read more

Laravel redirect back to original destination after login

For Laravel 5.3 and above Check Scott’s answer below. For Laravel 5 up to 5.2 Simply put, On auth middleware: // redirect the user to “/login” // and stores the url being accessed on session if (Auth::guest()) { return redirect()->guest(‘login’); } return $next($request); On login action: // redirect the user back to the intended page … Read more

Laravel – create model, controller and migration in single artisan command

You can do it if you start from the model php artisan make:model Todo -mcr if you run php artisan make:model –help you can see all the available options -m, –migration Create a new migration file for the model. -c, –controller Create a new controller for the model. -r, –resource Indicates if the generated controller … Read more

Select Last Row in the Table

You’ll need to order by the same field you’re ordering by now, but descending. As an example, if you have a time stamp when the upload was done called upload_time, you’d do something like this; For Pre-Laravel 4 return DB::table(‘files’)->order_by(‘upload_time’, ‘desc’)->first(); For Laravel 4 and onwards return DB::table(‘files’)->orderBy(‘upload_time’, ‘desc’)->first(); For Laravel 5.7 and onwards return … Read more

Migration: Cannot add foreign key constraint

Add it in two steps, and it’s good to make it unsigned too: public function up() { Schema::create(‘priorities’, function($table) { $table->increments(‘id’, true); $table->integer(‘user_id’)->unsigned(); $table->string(‘priority_name’); $table->smallInteger(‘rank’); $table->text(‘class’); $table->timestamps(‘timecreated’); }); Schema::table(‘priorities’, function($table) { $table->foreign(‘user_id’)->references(‘id’)->on(‘users’); }); }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)