Laravel is a framewrok, Framework mean the collection of tools, which is use to build a web application.
Environment setup for Laravel Installation
Install this software – links also given
- Xampp – https://www.apachefriends.org/download.html
- Composer – https://getcomposer.org/download/
- NPM – https://nodejs.org/en/download/
- VS Code – https://code.visualstudio.com/download
Check that Xampp is Installed and Working
Check Composer Intalled and Working
composer -v
Check NPM Intalled and Working
npm -v
Clear command on the CMD/POWERSHELL
cls
VS Code Extension
https://marketplace.visualstudio.com/items?itemName=onecentlin.laravel-extension-pack
Laravel Goto
https://marketplace.visualstudio.com/items?itemName=absszero.vscode-laravel-goto
https://marketplace.visualstudio.com/items?itemName=mohamedbenhida.laravel-intellisense
https://marketplace.visualstudio.com/items?itemName=shufo.vscode-blade-formatter
https://marketplace.visualstudio.com/items?itemName=MehediDracula.php-namespace-resolver
Laravel Installation
composer create-project laravel/laravel your-project-name
specific version instal
composer create-project Laravel/Laravel:^10.0 p1 //here 10 is the version
Tutorial – Laravel Instatallation https://youtu.be/1ia4nzXbiwg
Make Authentication (LOGIN/SIGNUP System)
> Database Connection
> composer require laravel/ui
> php artisan ui bootstrap ––auth (Write this, no copy)
> npm install
> npm run build
> npm run dev
> php artisan migrate
Make Authentication (LOGIN/SIGNUP System) (New)
> Database Connection
> composer require laravel/breeze –dev
> php artisan breeze:install blade
> php artisan migrate
What is artisan?
Artisan is a powerful command-line interface (CLI) tool included with the Laravel framework. It provides a set of useful commands that automate common development tasks, making your Laravel development experience more efficient and streamlined.
Setup Admin Panel with Laravel
- Need an admin panel.
- Analysis it.
- Setup with Laravel view+layout.
- Controller setup
- Route setup
Role Management in Authentication
Necessary Command
php artisan make:migration add_role_in_users_table --table=users
php artisan make:middleware AdminMiddleware
Add this in migration, that created in last.
//column created
$table->integer('role')->default(0);
//column drop
$table->dropColumn('role');
Role logic
if(Auth::check()){
if(Auth::user()->role == '1'){
return $next($request);
}else{
return redirect('/');
}
}else{
return redirect('');
}
Make route
Route::prefix('admin')->middleware(['auth','isAdmin'])->group(function(){
//url
});
Some command
php artisan make:controller ControllerName
php artisan make:controller Folder/ControllerName
php artisan make:controller ControllerName -r
php artisan make:controller Folder/ControllerName -r
php artisan optimize
php artisan make:migration create_table_name
php artisan make: model model_name
php artisan make:migration add_new_fields_user_table –table=users
@if(!$products->isEmpty())
@else
<h3>No Product Available Currently</h3>
<h3>Please visit after sometimes</h3>
@endif
Image Intervention Package Install
composer require intervention/image
file = $request['photo'];
$image_name = uniqid('user_').'_'.rand().'.'.$request['photo']->getClientOriginalExtension();
Image::make($file)->save(public_path('/sujon/'.$image_name));
Image::make($request['photo'])->save(public_path('uploads/student/'.$image_name)); //raw
for Laravel 11
https://image.intervention.io/v3/introduction/upgrade
https://image.intervention.io/v3/introduction/frameworks
composer require intervention/image-laravel
php artisan vendor:publish --provider="Intervention\Image\Laravel\ServiceProvider"
use Intervention\Image\Laravel\Facades\Image;
create image name:
$image_name = uniqid('user_').'_'.rand().'.'.$request['photo']->getClientOriginalExtension();
save:
Image::read($request['photo'])->save(public_path('uploads/student/'.$image_name));
Some quick command
//For rollback one step
php artisan migrate:rollback --step=1
//Rollback specific migration
php artisan migrate:rollback --path=/database/migrations/migration_file_name.php
//sample
php artisan migrate:rollback --path=/database/migrations/2022_12_26_144352_create_agri_infos_table.php
//active class add
{{ request()->is('/') ? 'active' : ''}}
// ternary operator
{{ $single_order->order_status == 0 ? 'Pending' : 'Completed' }}
//Confirm with Jquery
<a onclick="return window.confirm('Are you sure?');" href="{{url('vet/me/farmerissue/solve/'.$data->id)}}">Solve</a>
Laravel Resource Controller, Model, Migration create
php artisan make:model Model_Name -mcr
Resource route:
Route::resource('/student', StudentController::class);
Laravel Create
In store method
Student::create($request->all());
also return view possible
Laravel Read
$data = Model::all();
then compact in view
$data = Model::paginate(1);
{{$data->links()}}
Laravel Route Check
php artisan route:list
Laravel Version Check Command
php artisan --version
{{ phpversion() }} //blade view php version
{{ app()->version() }} //blade view laravel version
php artisan about //all info view
check composer.json
check directory
vendor/laravel/framework/src/Illuminate/Foundation/Application.php
Soft Delete in Laravel
Add a column deleted_at
php artisan make:migration add_delete_column_student_table --table=students
Migration file up:
$table->softDeletes();
Migration file down:
$table->dropSoftDeletes();
Migrate it.
On model
use Illuminate\Database\Eloquent\SoftDeletes;
use SoftDeletes;
or
use HasFactory,SoftDeletes;
$data = Model::onlyTrashed()->get();
public function hard_delete($id)
{
$forceDelete = Student::where('id',$id)->forceDelete();
return $forceDelete;
}
Encrypt Password Tool For Laravel
https://bcrypt-generator.com/
uniqid()
now()
use Hash;
use Carbon\Carbon;
Laravel Auth Check
use Illuminate\Routing\Controller;
__construct for auto trigger
$this->middleware('auth');
Package Uninstall
composer uninstall laravel/package_name
404 Page Error Page
Open a errors folder inside views folder, and add 404.blade.php page.