- is a PHP project to learn basics of laravel
composer create -project laravel/laravel name-project
php artisan serve
composer require laravel/breeze --dev
php artisan breeze:install blade --dark
- on the file .env change the name of DB_DATABASE
- on DBMS create the database with the same name of before step
- on the explorer choose run migrations
composer require laravel-lang/common --dev
- add support to espanish
php artisan lang:add es
- or support to fr
php artisan lang:Add fr
note: publish always lang on english for default
php artisan lang:publish
- on 'locale' => 'en' change to 'locale' => 'es'
- in this file add lang on login and register
- for lang use the next sintax:
{{__('name_variable')}}
- change the file on lang > language > language.json
- to create env variables add the variable on .env with the next sintax:
NAME_VARIABLE=VALUE
- to use env variables
env('NAME_VARIABLE', 'DEFAULT_VALUE')
- always add on .env.example when you add new line on .env
- structure:
Route::method('/url', function(){
return //message or view(nameView);
});
- endpoint with params
Route::method('/url/{param}', function($variable){
return 'message'.$variable;
});
- optional params
Route::method('/url/{param?}', function($variable = dafaultValue){
return 'message'.$variable;
});
- redirect
Route::method('/url/{param?}', function($variable){
if($variable == value){
return redirect('/url');
}
return 'message'.$variable;
});
- endpoint name
Route::method('/url/{param}', function($variable){
return 'message'.$variable;
})->name('name.index'); // .index .create .show is a convention
- redirect to endpoint name
Route::method('/url/{param?}', function($variable){
if($variable == value){
return redirect()->route('name.index');
}
return 'message'.$variable;
});
or
Route::method('/url/{param?}', function($variable){
if($variable == value){
return to_route('name.index');
}
return 'message'.$variable;
});
- only return a view
Route::view('/url', 'view');
//or with name
Route::view('/url', 'view')->name('welcome');
- view all defined routes
php artisan route:list
- only on application
php artisan route:list --except-vendor
- is a constant route o endpoint to home in this case is '/dashboard'. is ubicate on file RouteServiceProvider
-
execute something after and before the route is executed
-
how to use:
Route::get('/url', function (){
return //function, view o something
})->middleware(['beforeMiddleware', 'afterMiddleware'])->name('endpointName')
- inheritance middleware
Route::middleware('nameMiddleware')->group(function(){
Route::method('/url', action)->name('endpointName')
})
- on file >resources>views>layouts>navigation.blade.php modify navigation links and responsive navigation menu to include new routes
- create migration and controller:
php artisan make:model Name -mrc
- function up
php artisan migrate
- function down of the last lote
php artisan migrate:rollback
- function down of the last #n of migrations
php artisan migrate:rollback --step=numberOfMigrations
- is a Laravel ORM
- on app>Models>NameModel.php
class NameModel extends Model
{
use HasFactory;
protected $fillable = [
'fillName1',
'fillName2'
];
}
- how to use
use App\Models\NameModel;
NameModel::operation([
'fillName1'=>$variable,
'fillName2'=>'value' // or num
]);
- on runtime
npm run dev
- compile styles (Note: Only compile the styles what are when exec the comand)
npm run build
- on routes
Route::method('/url', function(){
session()->flash('status','message');
return to_route('name.index');
});
Route::method('/url', function(){
return to_route('name.index')->with('status','message'); // __('message') to i8n
});
- on controller ππΌ
public function nameFunction(){
session()->flash('status','message');
return to_route('name.index');
}
public function nameFunction(){
return to_route('name.index')->with('status','message'); // __('message') to i8n
}
- on views
@if(session('status'))
<div class="">{{ session('status')}}</div>
@endif
- on routes
Route::method('/url', [NameController::class, 'function'])->name('name.convention');
- on controller
public function nameFunction(){
//all code
return view('name.convention') //or to_route('name.convention') //with ->('nameSessionFlashMessage', 'value'); // or __('value') to i8n
}
- directive @csrf (cross-site-request-forgery) to prevent csrf vulnerability
<form method="method" action="{{route('name.convention')}}">
@csrf
</form>
$request->validate([
'nameToValidate'=>'required', // or rule to validate
'nameToValidate'=> ['required', 'min:3'] // rules
]);
- save value if have error validation of form
<textarea name="name"> {{old('name')}} </textarea>
- directive of Blade @dump
@dump($errors) //to see all errors
@dump($errors->get('tweet')) //to see tweet errors
- directive of Blade @error
@error('name'){{$message}}@enderror
- error to change style
<a class="@error('name') dark:border-red-300 @enderror">
- x-input-error of brezee
<x-input-error class="" :messages="$errors->get('name')"
- to change timezone you need go to config/app.php to change attribute timezone
@if
@endif
- !if
@unless
@endunless
- eq -> is equal? response with bool
eq()
- is -> compare if a model is the actual model
@if(auth()->user()->is(tweet->user))
// or
@if (auth()->user()->id === $tweet->user_id)
php artisan make:policy NamePolicy --model=Name
npm run build # to compile
- tailwind colors
https://tailwindcss.com/docs/customizing-colors
- tailwind align
https://tailwindcss.com/docs/text-align
- laravel eloquent
https://laravel.com/docs/10.x/eloquent#inserts
- laravel validation rules
https://laravel.com/docs/10.x/validation#available-validation-rules
- Timezone
https://www.php.net/manual/en/timezones.america.php
2024_01_19_222432_create_tweets_table ........... 30ms FAIL
Illuminate\Database\QueryException
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1 (Connection: mysql, SQL: alter table `tweets` add constraint `tweets_user_id_foreign` foreign key (`user_id`) references `users` (`id`) on delete )
at vendor\laravel\framework\src\Illuminate\Database\Connection.php:822
818β $this->getName(), $query, $this->prepareBindings($bindings), $e
819β );
820β }
821β
β 822β throw new QueryException(
823β $this->getName(), $query, $this->prepareBindings($bindings), $e
824β );
825β }
826β }
1 vendor\laravel\framework\src\Illuminate\Database\Connection.php:574
PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1")
2 vendor\laravel\framework\src\Illuminate\Database\Connection.php:574
PDO::prepare("alter table `tweets` add constraint `tweets_user_id_foreign` foreign key (`user_id`) references `users` (`id`) on delete ")
- solution:
alter table `tweets` add constraint `tweets_user_id_foreign` foreign key (`user_id`) references `users` (`id`) on delete cascade;
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:
- Simple, fast routing engine.
- Powerful dependency injection container.
- Multiple back-ends for session and cache storage.
- Expressive, intuitive database ORM.
- Database agnostic schema migrations.
- Robust background job processing.
- Real-time event broadcasting.
Laravel is accessible, powerful, and provides tools required for large, robust applications.
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.
You may also try the Laravel Bootcamp, where you will be guided through building a modern Laravel application from scratch.
If you don't feel like reading, Laracasts can help. Laracasts contains over 2000 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.
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 Partners program.
- Vehikl
- Tighten Co.
- WebReinvent
- Kirschbaum Development Group
- 64 Robots
- Curotec
- Cyber-Duck
- DevSquad
- Jump24
- Redberry
- Active Logic
- byte5
- OP.GG
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the Laravel documentation.
In order to ensure that the Laravel community is welcoming to all, please review and abide by the Code of Conduct.
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.
The Laravel framework is open-sourced software licensed under the MIT license.