Random Laravel ressources

This post contains a list of random useful resources, regarding some pretty common Laravel solutions. Consider it as a kind of shortcut to a lot of googling.

Laravel 5.7 from scratch

Best “getting started” guide if you are into video tutorials.

The “max key length is 767 bytes” problem

As described here, but in brief, you should open the file app/Provider/AppServiceProvider.php and add code to the boot() method as bellow

use Illuminate\Support\Facades\Schema;

     * Bootstrap any application services.
     * @return void
    public function boot()

Since the tables are actually created when you try to perform the migration without the above code, you should drop the database and recreate it before retrying to run the migration again (or at least drop all tables). Failing to do so will result in one more error instructing you that the table ‘users’ already exists.

Console output methods

From the manual

To send output to the console, use the lineinfocommentquestion and error

Laravel Documentation

Many to many relatioship using eloquent

Try this excellent guide.

Pivot table names in alphabetical order

What the above article does not mention is an important detail in the naming convention of the pivot table.

Name of the pivot table should consist of singular names of both tables, separated by underscore symbol and these names should be arranged in alphabetical order, so we have to have product_shop, not shop_product

Laravel daily

Seeder throw error Class does not exist

When you write a new seeder, chances are it will throw an error

Seeding: UsersTableSeeder

   ReflectionException  : Class UsersTableSeeder does not exist

Just keep calm and dump your autoloader.

composer dump-autoload

For details see this stackoverflow question