What Are the Differences Between PSR-0 and PSR-4?

Recently I’ve read about namespaces and how they are beneficial. I’m currently creating a project in Laravel and trying to move from class map autoloading to namespacing. However, I can’t seem to grasp what the actual difference is between PSR-0 and PSR-4. Some resources that I’ve read are… Battle of the Autoloaders Laracasts PSR-4 autoloading … Read more

How to place the ~/.composer/vendor/bin directory in your PATH?

I’m on Ubuntu 14.04 and I’ve been trying all possible methods to install Laravel to no avail. Error messages everything I try. I’m now trying the first method in the quickstart documentation, that is, via Laravel Installer, but it says to “Make sure to place the ~/.composer/vendor/bin directory in your PATH so the Laravel executable … Read more

Target class controller does not exist – Laravel 8

Here is my controller: <?php namespace App\Http\Controllers\Api; use App\Http\Controllers\Controller; use Illuminate\Http\Request; class RegisterController extends Controller { public function register(Request $request) { dd(‘aa’); } } As seen in the screenshot, the class exists and is in the correct place: My api.php route: Route::get(‘register’, ‘Api\RegisterController@register’); When I hit my register route using Postman, it gave me the … Read more

Add a custom attribute to a Laravel / Eloquent model on load?

I’d like to be able to add a custom attribute/property to an Laravel/Eloquent model when it is loaded, similar to how that might be achieved with RedBean’s $model->open() method. For instance, at the moment, in my controller I have: public function index() { $sessions = EventSession::all(); foreach ($sessions as $i => $session) { $sessions[$i]->available = … Read more

Laravel Migration Error: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

Migration error on Laravel 5.4 with php artisan make:auth [Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter tabl e users add unique users_email_unique(email)) [PDOException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes … Read more

Laravel: How to Get Current Route Name? (v5 … v7)

In Laravel v4 I was able to get the current route name using… Route::currentRouteName() How can I do it in Laravel v5 and Laravel v6? 32 Answers 32 Try this Route::getCurrentRoute()->getPath(); or \Request::route()->getName() from v5.1 use Illuminate\Support\Facades\Route; $currentPath= Route::getFacadeRoot()->current()->uri(); Laravel v5.2 Route::currentRouteName(); //use Illuminate\Support\Facades\Route; Or if you need the action name Route::getCurrentRoute()->getActionName(); Laravel 5.2 route … Read more

PHP7 : install ext-dom issue

I’m running laravel 5.4 on Ubuntu 16.04 server with PHP7. trying to install cviebrock/eloquent-sluggable package throw some error: pish@let:/home/sherk/ftp/www$ sudo composer require cviebrock/eloquent-sluggable Do not run Composer as root/super user! See https://getcomposer.org/root for details Using version ^4.2 for cviebrock/eloquent-sluggable ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Your requirements … Read more

Laravel Migration Change to Make a Column Nullable

I created a migration with unsigned user_id. How can I edit user_id in a new migration to also make it nullable()? Schema::create(‘throttle’, function(Blueprint $table) { $table->increments(‘id’); // this needs to also be nullable, how should the next migration be? $table->integer(‘user_id’)->unsigned(); } 11 Answers 11