Posts

Illuminate\Database\QueryException SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (Connection: mysql, SQL: alter table `roles` add unique `roles_role_name_unique`(`role_name`)) in Laravel 11

Image
  SOLUTION: When Above error is occurred at that time we have to specify length in column name. If we specify only column name in migration file the above error is occurred. For Example, if we specify only varchar instead of varchar(50) then above error is occurred. So To solve above Error, we have to specify column length as shown below image. In below image, we have specified $table->string("role_name",50)->unique();

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'many_to_many.sessions' doesn't exist (Connection: mysql, SQL: select * from `sessions` where `id` = tVoFh2Iof0GJWye33iUipBBOWNXELZCejzrC4vO0 limit 1) in Laravel 11

Image
  SOLUTION : Above Error is due to below code in Laravel 11 .env file: To Solve Above Error we have to change SESSION_DRIVER=database to SESSION_DRIVER=file. By Changing "database" to "file", above Error will Solve as shown below.

Internal Server Error Illuminate\Database\Eloquent\MassAssignmentException Add [name] to fillable property to allow mass assignment on [App\Models\User]. in Laravel 11

Image
  SOLUTION : IN app\Models\User File, add below code to solve above Error <?php namespace App\Models ; use Illuminate\Database\Eloquent\ Model ; class User extends Model {     public $timestamps = false ;     // protected $guarded = [];     //we can write $guarded OR $fillable variable     protected $fillable = [ "name" , "email" , "age" , "city" ]; }

Internal Server Error Exception Property [name] does not exist on this collection instance. in Laravel 11

Image
  SOLUTION : In app\Http\Controllers\UserController File Update public function show ( User $user )     {         $users = User :: find ( $user );         return view ( "viewuser" , compact ( "users" ));     } This Error is occurred due to above code. So Change above code as shown below : public function show ( string $id )     {         $users = User :: find ( $id );         return view ( "viewuser" , compact ( "users" ));     }