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

The problem is caused by the fact that the Model‘s toArray() method ignores any accessors which do not directly relate to a column in the underlying table. As Taylor Otwell mentioned here, “This is intentional and for performance reasons.” However there is an easy way to achieve this: class EventSession extends Eloquent { protected $table=”sessions”; … Read more

Error “Target class controller does not exist” when using Laravel 8

You are using Laravel 8. In a fresh install of Laravel 8, there is no namespace prefix being applied to your route groups that your routes are loaded into. “In previous releases of Laravel, the RouteServiceProvider contained a $namespace property. This property’s value would automatically be prefixed onto controller route definitions and calls to the … Read more

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

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 documentation Retrieving The Request URI The path method returns the request’s URI. So, if the incoming request is targeted at http://example.com/foo/bar, the path method will return foo/bar: $uri … Read more

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

According to the official Laravel 7.x documentation, you can solve this quite easily. Update your /app/Providers/AppServiceProvider.php to contain: use Illuminate\Support\Facades\Schema; /** * Bootstrap any application services. * * @return void */ public function boot() { Schema::defaultStringLength(191); } Alternatively, you may enable the innodb_large_prefix option for your database. Refer to your database’s documentation for instructions on … Read more

Laravel Migration Change to Make a Column Nullable

Laravel 5 now supports changing a column; here’s an example from the offical documentation: Schema::table(‘users’, function($table) { $table->string(‘name’, 50)->nullable()->change(); }); Source: http://laravel.com/docs/5.0/schema#changing-columns Laravel 4 does not support modifying columns, so you’ll need use another technique such as writing a raw SQL command. For example: // getting Laravel App Instance $app = app(); // getting laravel … Read more

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