basicslaravelblog-pagebeginner
laravel basics of basics
2 min read
introduction
- a few of our friends are thinking of making a community based on learning, discussing and sharing materials and learned wisdom
- us as the initiators of this community can not be complacent
- thus leading to this
- us starting a new journey
problems
- of course no one will remember but today there was problems with wifi and electricity
- i could not perform at the level that I wanted to perform in
- so I could only cover a very very small part of the content which is blade and backend connection
learnings
- best practice for passing data from controller to the view is to use compact
return view('page.home', compact('content'));
- when creating a model, always use the following command
php artisan make:model Post -a- This creates the following files
- Post model
- PostController
- StorePostRequest
- UpdatePostRequest
- PostFactory
- PostSeeder
- PostPolicy
YYYY_MM_DD_HHMMSS_create_post_tablemigration- YYYY = current year
- MM = current month
- DD = current date
- HH = current hour
- MM = current minute
- SS = current second
- So if a model for Post using
-awas created at- 2026/06/06 11:32:43 am
- it would be
2026_06_06_113243_create_posts_table.php
- creating controller like this makes a resource controller
- index = get all item
- create = show form to create new item
- store = create new item
- show = show an item
- edit = show form to edit an item
- update = update an item
- destroy = delete an item
- To pass data from controller to blade view, we use the compact parameter of view function
return view('page.home', compact('variable'));- the 'page.home' means the resources/views/page/home.blade.php file
- the 'variable' means the $variable present in the same scope as the return statement
- To show the passed data in the blade view, we just cover it in curly braces
- the
{{ $variable }}renders the passed content as string - the
{!! $variable !!}renders the passed content as raw value (i.e, html, css, js, etc)- NOTE: using {!! !!} can lead to XSS infiltration
- the