Init Laravel project
Debug Bar
- Open the vs code or whatever you use as code editor and in the termenal add this line of code and press enter"
- Add this line to config/app file in the providers
- Add this line to config/app file in the aliases
- Add this line route folder inside web.php in the home route"
- Publish the debug bar package in the project"
- Connect project to mySql Database"
- "Start mySql and server using Xaamp or any similer app provide same services"
- "Press on the GO to app folder button"
composer require barryvdh/laravel-debugbar --dev
Barryvdh\Debugbar\ServiceProvider::class,
'Debugbar' => Barryvdh\Debugbar\Facades\Debugbar::class,
Debugbar::info('info');
php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider"
php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider"
Create data base and set the env file to connect to it
UI Setup
- run this command:
- run this command
- Create main.scss inside resources
- Create main.css inside public css folder
- go to resources/view/layouts/app.php and add this line of code in the head
- run this command
- run this command to install mix:
- run this command
- helper commands if needed
composer require laravel/ui
php artisan ui bootstrap --auth
link href="https://codewithammar.com/css/main.css" rel="stylesheet"
npm install && npm run dev
npm install laravel-mix@latest
npm run watch
npm clean-install
npm run build
"watch": "webpack --watch --progress"
Set admin and users roles
- run this commands:
- Past this line in databases/seeders/DatabaseSeeder.php inside the function
- run this commands:
- Go to app/http/controllers/auth/RegisterController.php and add this code to the create function
composer require santigarcor/laratrust
php artisan vendor:publish --tag="laratrust"
php artisan laratrust:setup
php artisan laratrust:seeder
php artisan vendor:publish --tag="laratrust-seeder"
composer dump-autoload
$this->call(LaratrustSeeder::class);
php artisan migrate
php artisan db:seed
->attachRole('user');
Setup Multi Languages
- Go to app/config/app.php and set the defualt local by set local key to whatever you want :
- run this command to create a language middleware and after that replace the code inside the class with:
- add the created middleware to "WEB" key in the kernel file to run it from all app Go to app/http/kernel.php
- Create file named languages inside the config folder contain this code:
- Create controller named LanguagesController:
- replace the code inside the controller with:
- Create a new route inside routes/wep.php file
- Add the flags to projects using this code
- inside resources/ sass / app.sass add this code to link flags
- run this code
- add this dropdwon items to layouts folder inside app.blade.php
- Create the languages folders and files to the lang folder
- Simply use it like this from blade
- and like this from controllers
Step 1
'locale'=>'en'
Step 2
use Illuminate\Support\Facades\App;
public function handle(Request $request, Closure $next)
{
if (Session()->has('applocale') and array_key_exists(Session()->get('applocale'),
config('languages'))) {
App::setlocale(Session()->get('applocale'));
} else {
App::setlocale(config('app.fallback_locale'));
}
return $next($request);
}
Step 3
\App\Http\Middleware\Language::class,
Step 4
php
return [
'en' => [
'display' => 'English',
'flag-icon' => 'us',
],
'ar' => [
'display' => 'Arabic',
'flag-icon' => 'sa',
],
];
Step 5
php artisan make:controller LanguagesController
php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Redirect;
class LanguagesController extends Controller
{
public function switchLang($lang)
{
if (array_key_exists($lang, Config::get('languages'))) {
Session::put('applocale', $lang);
}
return Redirect::back();
}
}
Step 6
Route::get('lang/{lang}', ['as' => 'lang.switch', 'uses' =>
'\App\Http\Controllers\LanguagesController@switchLang']);
Step 7
npm install flag-icons
@import '~flag-icons/css/flag-icons.css';
npm run watch
Step 8
See the code
Step 9
?php
return [
'whoAreWe' => 'Who Are We ?',
];
Step 10
about.whoAreWe
trans('about.whoAreWe');