- https://laravel.com/docs/8.x/releases (Documentation)
- https://laravel.com/docs/8.x/starter-kits (Starter Kits)
- Installation
-
laravel new <repo_name>
(add--auth
if you want Authentication ) if you have laravel install as a global package -composer global require laravel/installer
-
composer create-project --prefer-dist laravel/laravel <repo_name>
- Serve app by using
php artisan serve --port=8081
, if vhost is used, URL : http://blog.laravel.local:8081/ - Controllers located at
app/Http/Controller/
php artisan storage:link
create symlink in<app_name>/public/
for<app_name>/storage/app/public/
- Routes
routes/web.php
- Auth & check role middleware - Models are named singular and tables are created in plural
- Helpers :
-
- In repo :
Utils/helper.php
- In repo :
-
- Added in
composer.json
-autoload
section, thencomposer dump-autoload
- Added in
-
- Used in
resources/views/admin/posts.blade.php
- Used in
- Routes admin -
adminPostEdit
updated for multiple parameter php artisan route:list
- Routes list
composer require laravel/ui
for GUI- Then
php artisan ui:auth
(get list byphp artisan list
) - Files created :
resources/views/auth
&app/Http/Controllers/Auth
- Added middleware -
app/Http/Middleware/CheckRole.php
- Register class in
app/Http/Kernel.php
- Run
npm install
- Some packages were missing, so
npm install less-loader --save-dev
&npm install stylus stylus-loader --save
- Then
npm run dev
- Check
webpack.mix.js
&package.json
config/database.php
&.env
hold DB connection details and type of database used- Connect to MySQL CLI using command prompt by
mysql -u <username> -p
, then type your password. -
show databases;
-
use your_database_name;
-
show tables;
-
desc your_table_name;
php artisan make:model <NAME>
- file created inapp\Models
andphp artisan make:migrations <your_migration_name>
- file created indatabase/migrations
- N.B -
php artisan make:modeal <NAME> -m
- create model & migration directly - Create your table structure in the newly created migration
Schema::create('cars', function (Blueprint $table) {
$table->increments('id');
$table->string('model_name');
$table->longText('information');
$table->integer('year');
});
- After migrations are created,
php artisan migrate
ORphp artisan migrate:install
- Might need to add fix in
app\Providers\AppServiceProvider
- Some commands :
-
php artisan migrate:reset
- rollback
-
php artisan migrate:refresh
- rollback & migrate
-
php artisan migrate:status
- Get information
php artisan make:factory PostFactory --model=Post
- create file indatabase/factories
based on model argument- Use of laravel/tinker by
php artisan tinker
for table population (N.B changeprotected $model
in<NAME>Factory.php
) and populate by : -
\App\Models\User::factory()->count(5)->create();
- create 5 users (N.B Models should haveuse HasFactory;
)
-
\App\Models\Post::factory()->count(7)->create();
- create 7 posts
-
\App\Models\Comment::factory()->count(15)->create();
- create 15 comments
-
\App\Models\Car::factory()->count(10)->create();
- create 10 cars
- Code in
app/Http/Controllers/PubloicController.php
, methods :carsList
&carSingle
- More about DB in
<project>\vendor\laravel\framework\src\Illuminate\Support\Facades\DB.php
php artisan make:controller CarsController --resource
- create controller with CRUD methods- In
web.php
, addRoute::resource('car-lists', \App\Http\Controllers\CarsController::class);
, then routes will be created automatically
| | POST | car-lists | car-lists.store | App\Http\Controllers\CarsController@store | web |
| | GET|HEAD | car-lists | car-lists.index | App\Http\Controllers\CarsController@index | web |
| | GET|HEAD | car-lists/create | car-lists.create | App\Http\Controllers\CarsController@create | web |
| | PUT|PATCH | car-lists/{car_list} | car-lists.update | App\Http\Controllers\CarsController@update | web |
| | DELETE | car-lists/{car_list} | car-lists.destroy | App\Http\Controllers\CarsController@destroy | web |
| | GET|HEAD | car-lists/{car_list} | car-lists.show | App\Http\Controllers\CarsController@show | web |
| | GET|HEAD | car-lists/{car_list}/edit | car-lists.edit | App\Http\Controllers\CarsController@edit | web |
- Eloquent URLs :
-
<app_url>/car-lists
- Show all
-
<app_url>/car-lists/<ID>
- Show single
-
<app_url>/car-lists/create
- Create New entry - Not good way, only for example
-
<app_url>/car-lists/<ID>/edit
- Edit single & Delete - Not good way, only for example
- Codes are in
app/Http/Controllers/CarController.php
&app\Http\Controllers/PublicController.php
-
<app_url>/posts-manipulation/<ID>
- use
@csrf
- use
@method('delete')
- for delete - use
@method('PUT')
- for update
- https://laravel.com/docs/8.x/telescope (Docs for setup)
- Install
composer require laravel/telescope --dev
- Then run
php artisan telescope:install
- publish its assets - Then run
php artisan migrate
- create the tables needed to store Telescope's data - Finally goto
<app_url>/telescope
to view dashboard - Having a debug bar :
-
- Install
composer require barryvdh/laravel-debugbar --dev
- Install
-
- In
config/app.php
, add :
- In
-
-
Barryvdh\Debugbar\ServiceProvider::class,
inproviders
-
-
-
'Debugbar' => Barryvdh\Debugbar\Facade::class,
inaliases
-
-
- Then run
php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider"
- createdebugbar.php
inconfig
repo
- Then run
- Activate / Deactivate it in
.env
- Create custom request validation :
php artisan make:request CreateValidationRequest
- created inapp\Http\Requests
- Create custom made rule :
php artisan make:rule Uppercase
- created inapp\Rules
, check usage inapp\Http\Request\CreatePost.php
php artisan clear-compiled
: Clear thebootstrap/cache
repophp artisan down
: 503 - Service unavailablephp artisan up
: Use afterdown
php artisan env
: Show current environmentlocal
php artisan --version
: Laravel version usedphp artisan optimize
: Cache generation optimizedphp artisan cach:clear
: application cache clearedphp artisan auth:clear-reset
: Clearing expired reset tokensphp artisan key:generate
:APP_KEY
in.env
resetphp artisan session:table
followed byphp artisan migrate
, will create session table in DB, then changeSESSION_DRIVER
in.env
todatabase
to use the create tablephp artisan view:clear
: Clear compiled viewphp artisan ui ...
- https://laravel.com/docs/7.x/frontend (Documentation)