Build Status Total Downloads Latest Stable Version License

Shortcuts for Rocky

boot up the server

Fresh install of repo?

  1. npm start
  2. composer install
  3. php artisan key:generate
  4. php artisan serve
  5. make sure database is connected
  6. ensure .env file exists and loads (it's the default rootpassword)
  7. Create a few blog posts -- http://127.0.0.1:8000/articles/create

Kick it off? php artisan serve

LINUX: http://localhost/phpmyadmin/ need to restart apache? sudo service apache2 restart

make things

php artisan make:xxx -xx

public vs resources folder?

public - you can put pure js/html/css in there resources are things that need to be compiled down.

compile scss into css

Get npm up and running --> npm install

Then in your webpack, modify things.

in webpack.mix.js
(entrypoint, and output)
FROM:
mix.js('resources/js/app.js', 'public/js')
  .sass("resources/sass/app.scss", "public/css");

TO:
mix.sass("resources/sass/app.scss", "public/css");

Next npm run dev

to make it watch -- npm run watch

Finally, import it into your file.

OR use the mix function

Adding data rows to table

php artisan tinker

$prop = new App\PROP

$prop->value = "new value here"
$prop->data = "new data here"

$prop //to review

$prop->save();

CRUD method for a controller

index = show all list
show = show single resource
create = to create new resource
store = save your new creation
edit = to modify resource
update = save your edit
destroy = to destroy it


php artisan make:controller THINGController -r

//this will create the model and tie it to the controller as well.
php artisan make:controller THINGController -r -m THING

CRUD but for routing

http web verbs : GET, POST, PUT, DELETE

GET /articles
GET /articles/:id
GET /articles/:id/edit
GET /articles/create

POST /articles
PUT /articles/:id
DELETE /articles/:id

REST
Route::get('/articles', 'ArticlesController@index');
Route::get('/articles/{article}', 'ArticlesController@show');
Question: How to use Restful Routing and static pages like about us together? Should I create a route like this Route::get("about-us", 'AboutUsController@index') ?

ANSWER: Don't bother. I typically create a PagesController for all static pages. So you'd have actions like PagesController@about, PagesController@contact, etc.

Want to debug requests?

   public function store()
    {
        // die('hello'); // get something to show
        // dump(request()->all()); //show all the data

        $article = new Article();

        // pass article data over
        $article->title = request('title');
        $article->excerpt = request('excerpt');
        $article->body = request('body');

        $article->save();

        // redirect
        return redirect('/articles');
    }

If you want to test it.

    php artisan tinker
    $user = App\User::find(1);
    $user->articles;

Get the request query

if (request('tag')) { }

Autogenerate fake SQL data

  1. php artisan tinker
  2. factory(App\User::class, 7)->create(); //this creates 7 users

If you want to override factory(App\Article::class, 5)->create(['title'=> 'Override the title']);

so to override it to assign the new articles for a specific user factory(App\Article::class, 5)->create(['user_id'=> '1']);

Cleaner output

In php artisan tinker

>>> $article->tags;
=> Illuminate\Database\Eloquent\Collection {#3029
     all: [
       App\Tag {#3019
         id: 1,
         name: "laravel",
         created_at: "2020-01-30 00:00:00",
         updated_at: "2020-01-30 00:00:00",
         pivot: Illuminate\Database\Eloquent\Relations\Pivot {#3035
           article_id: 1,
           tag_id: 1,
         },
       },
       App\Tag {#3022
         id: 2,
         name: "php",
         created_at: "2020-01-30 00:00:00",
         updated_at: "2020-01-30 00:00:00",
         pivot: Illuminate\Database\Eloquent\Relations\Pivot {#3023
           article_id: 1,
           tag_id: 2,
         },
       },
       App\Tag {#3036
         id: 3,
         name: "education",
         created_at: "2020-01-30 00:00:00",
         updated_at: "2020-01-30 00:00:00",
         pivot: Illuminate\Database\Eloquent\Relations\Pivot {#3033
           article_id: 1,
           tag_id: 3,
         },
       },
     ],
   }
>>> $article->tags->pluck('name');
=> Illuminate\Support\Collection {#3032
     all: [
       "laravel",
       "php",
       "education",
     ],
   }

Eloquent Recipes

Attaching a tag

$article->tags()->attach(1)

//This takes the variable you created, visits the tag method, and uses the attach (1).

$article->tags()->attach([2,3])

//same, but with an array.

detach is the opposite.

$article->tags()->detach([2,3])

$tag = App\Tag::find(1); => App\Tag {#3033 id: 1, name: "laravel", created_at: "2020-01-30 00:00:00", updated_at: "2020-01-30 00:00:00", }

$article->tags()->attach($tag); $tag = App\Tag::find(2);

You can provide a single ID. You can provide an array. You can provide a model. You canprovide an array of models.

About Laravel

Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:

Laravel is accessible, powerful, and provides tools required for large, robust applications.

Learning Laravel

Laravel has the most extensive and thorough documentation and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.

If you don't feel like reading, Laracasts can help. Laracasts contains over 1500 video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.

Laravel Sponsors

We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the Laravel Patreon page.

Contributing

Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the Laravel documentation.

Code of Conduct

In order to ensure that the Laravel community is welcoming to all, please review and abide by the Code of Conduct.

Security Vulnerabilities

If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via taylor@laravel.com. All security vulnerabilities will be promptly addressed.

License

The Laravel framework is open-sourced software licensed under the MIT license.