php artisan serve
php artisan optimize:clear
php artisan config:cache
php artisan view:clear
php artisan cache:clear
php artisan route:cache
composer dump-autoload
php composer.phar global update
npm install bootstrap
npm install bootstrap-icons
1. Create new project:
#Via the installer
laravel new links
# Via composer
composer create-project laravel/laravel quickstart --prefer-dist
or
composer create-project --prefer-dist laravel/laravel links "8.*"
This will create a new directory at ~/Sites/links and install a new Laravel project.
2. Database Setup
open .env file and edit configuration like DB_DATABASE name etc.
3.test your database connection is running the migrate artisan command:
php artisan migrate
4. Create new table:
php artisan make:migration create_contactus_table --create=contactus
or
php artisan make:migration create_contactus_table
Now Open open the file: database/migrations/{{datetime}}_create_contactus_table.php
add the following schema:
Schema::create('contactus', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->string('url')->unique();
$table->text('description');
$table->timestamps();
});
Add new field in the contactus table:
install: composer require doctrine/dbal
php artisan make:migration add_email_to_contactus_table
5. Create Controller:
php artisan make:controller PhotoController --resource
This command will generate a controller at app/Http/Controllers/PhotoController.php.
6. Create new model (/app/models/Contactus)
php artisan make:model --factory Contactus
Model created successfully.
Factory created successfully.
7. Create controller and model:
php artisan make:controller PhotoController --resource --model=Photo
php artisan make:model article -mc //it will create model, controller and migration
/////////////////////////////////////////////////////
How to create modules
url: https://medium.com/@destinyajax/how-to-build-modular-applications-in-lar...
https://github.com/nWidart/laravel-modules
////////////////////////////////////////////////////
To install through Composer, by run the following command:
composer require nwidart/laravel-modules
The package will automatically register a service provider and alias.
Optionally, publish the package's configuration file by running:
php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider"
By default, the module classes are not loaded automatically. You can autoload your modules using psr-4. For example:
{
"autoload": {
"psr-4": {
"App\\": "app/",
"Modules\\": "Modules/"
}
}
}
run composer dump-autoload
------------------------------------------
Some important commands used with module:
https://nwidart.com/laravel-modules/v6/advanced-tools/artisan-commands
module:use
php artisan module:use Blog
module:unuse
php artisan module:unuse
List all available modules:
php artisan module:list
Migrate the given module, or without a module an argument, migrate all modules.
php artisan module:migrate Blog
Rollback the given module, or without an argument, rollback all modules.
php artisan module:migrate-rollback Blog
Refresh the migration for the given module, or without a specified module refresh all modules migrations.
php artisan module:migrate-refresh Blog
Reset the migration for the given module, or without a specified module reset all modules migrations.
php artisan module:migrate-reset Blog
Seed the given module, or without an argument, seed all modules
php artisan module:seed Blog
Publish the migration files for the given module, or without an argument publish all modules migrations.
php artisan module:publish-migration Blog
Publish the given module configuration files, or without an argument publish all modules configuration files.
php artisan module:publish-config Blog
Publish the translation files for the given module, or without a specified module publish all modules migrations.
php artisan module:publish-translation Blog
Enable the given module.
php artisan module:enable Blog
Disable the given module.
php artisan module:disable Blog
Update the given module.
php artisan module:update Blog
Generate the given console command for the specified module.
php artisan module:make-command CreatePostCommand Blog
Generate a migration for specified module.
php artisan module:make-migration create_posts_table Blog
Generate the given seed name for the specified module.
php artisan module:make-seed seed_fake_blog_posts Blog
Generate a controller for the specified module.
php artisan module:make-controller PostsController Blog
Generate the given model for the specified module.
php artisan module:make-model Post Blog
Optional options:
--fillable=field1,field2: set the fillable fields on the generated model
--migration, -m: create the migration file for the given model
Generate the given service provider name for the specified module.
php artisan module:make-provider BlogServiceProvider Blog
Generate the given middleware name for the specified module.
php artisan module:make-middleware CanReadPostsMiddleware Blog
Generate the given mail class for the specified module.
php artisan module:make-mail SendWeeklyPostsEmail Blog
Generate the given notification class name for the specified module.
php artisan module:make-notification NotifyAdminOfNewComment Blog
Generate the given listener for the specified module. Optionally you can specify which event class it should listen to. It also accepts a --queued flag allowed queued event listeners.
php artisan module:make-listener NotifyUsersOfANewPost Blog
php artisan module:make-listener NotifyUsersOfANewPost Blog --event=PostWasCreated
php artisan module:make-listener NotifyUsersOfANewPost Blog --event=PostWasCreated --queued
Generate the given request for the specified module.
php artisan module:make-request CreatePostRequest Blog
Generate the given event for the specified module.
php artisan module:make-event BlogPostWasUpdated Blog
Generate the given job for the specified module.
php artisan module:make-job JobName Blog
php artisan module:make-job JobName Blog --sync # A synchronous job class
Generate the given route service provider for the specified module.
php artisan module:route-provider Blog
Generate the given database factory for the specified module.
php artisan module:make-factory FactoryName Blog
Generate the given policy class for the specified module.
The Policies is not generated by default when creating a new module. Change the value of paths.generator.policies in modules.php to your desired location.
php artisan module:make-policy PolicyName Blog
Generate the given validation rule class for the specified module.
The Rules folder is not generated by default when creating a new module. Change the value of paths.generator.rules in modules.php to your desired location.
php artisan module:make-rule ValidationRule Blog
Generate the given resource class for the specified module. It can have an optional --collection argument to generate a resource collection.
The Transformers folder is not generated by default when creating a new module. Change the value of paths.generator.resource in modules.php to your desired location.
php artisan module:make-resource PostResource Blog
php artisan module:make-resource PostResource Blog --collection
Generate the given test class for the specified module.
php artisan module:make-test EloquentPostRepositoryTest Blog
-------------------------------------
#################################################################################
1. php artisan module:make User
2. php artisan module:make-migration create_users_table User
3. php artisan module:make-model User User
or
php artisan module:make-model User --migration User
4. php artisan module:migrate User
//( php artisan migrate:fresh //This command will drop all tables and create tables)
// php artisan migrate:fresh --seed
5. php artisan module:make-request UserRequest User
6. php artisan module:make-migration create_password_resets_table User
7. php artisan module:make-migration add_images_to_users_table User // add new column in users table
8. php artisan module:make-controller RoleController User
php artisan module:make-seed seed_fake_blog_posts Blog //Generate the given seed name for the specified module.
php artisan module:seed AclManage //insert dummy data available in /database/seeders folder
php artisan module:make-seed MasterDataSeeder ManageMaster
php artisan storage:link
composer dump-autoload
#####################################################################################
----------------------------------------------------
configure mail:
1. php artisan module:make-mail PasswordResetMail User
//Created : E:/xampp/htdocs/lara/laravel-dekho/Modules/User/Emails/PasswordResetMail.php
2. open file PasswordResetMail.php
public function build()
{
//return $this->view('view.name');
return $this->view('user::email'); //Under userController, created email() finction and also email.blade.php in views section
}
3. open any controller finction and implement mail e.g:
//Mail::to($request->user())->send(new PasswordResetMail());
or
Mail::to('tomail@test.com')
->cc('ccmail@test.com')
->bcc('bccmail@test.com')
->send(new PasswordResetMail());
-------------------------------------------------------
Configure Notification
1. php artisan notifications:table
2. php artisan module:make-model Message --migration User
Created : E:/xampp/htdocs/lara/laravel-dekho/Modules/User/Entities/Message.php
Created : E:/xampp/htdocs/lara/laravel-dekho/Modules/User/Database/Migrations/2020_10_21_145419_create_messages_table.php
3. php artisan migrate
4. php artisan make:notification NewMessage
5. Open app/Notifications/NewMessage.php
public $fromUser;
public function __construct(User $user){$this->fromUser = $user;}
public function toMail($notifiable)
{
$subject = sprintf('%s: You\'ve got a new message from %s!', config('app.name'), $this->fromUser->name);
$greeting = sprintf('Hello %s!', $notifiable->name);
return (new MailMessage)
->subject($subject)
->greeting($greeting)
->salutation('Yours Faithfully')
->line('The introduction to the notification.')
->action('Notification Action', url('/'))
->line('Thank you for using our application!');
}
6. php artisan module:make-controller NotificationController User
7. php artisan vendor:publish --tag=laravel-notifications
Copied Directory [\vendor\laravel\framework\src\Illuminate\Notifications\resources\views] To [\resources\views\vendor\notifications]
Publishing complete.
---------------------------------------------------
File Storage:
1. php artisan storage:link
The [E:\xampp\htdocs\lara\laravel-dekho\public\storage] link has been connected to [E:\xampp\htdocs\lara\laravel-dekho\storage\app/public].
The links have been created.
2. Open the controller file and add below code:
$fileName = time() . '.' . $request->file_upload->extension(); // file_upload is the name of the file in html
$name = $request->file('file_upload')->getClientOriginalName(); // file_upload is the name of the file in html
$extension = $request->file('file_upload')->extension(); // file_upload is the name of the file in html
$path = $request->file('file_upload')->storeAs('public/files/profile_pictures', $fileName); // file_upload is the name of the file in html
3. Display uploaded file in the html (.blade.php file):
@if($records['images'])
<img src="{{ asset('storage/'.$records['images']) }}" height="220" width="220" class="img-thumbnail">
@else
<img id="preview_img" src="{{ asset('storage/files/profile_pictures/img_dummy.png') }}" class="img-thumbnail" width="200" height="150"/>
@endif
--------------------------------------------------
Implementing ACL
E:\xampp\htdocs\lara\laravel-dekho-rnd>php artisan module:make-migration create_roles_table User
Created : E:/xampp/htdocs/lara/laravel-dekho-rnd/Modules/User/Database/Migrations/2020_10_19_115016_create_roles_table.php
E:\xampp\htdocs\lara\laravel-dekho-rnd>php artisan module:make-migration create_users_roles_table User
Created : E:/xampp/htdocs/lara/laravel-dekho-rnd/Modules/User/Database/Migrations/2020_10_19_115250_create_users_roles_table.php
E:\xampp\htdocs\lara\laravel-dekho-rnd>php artisan module:make-migration create_permissions_table User
Created : E:/xampp/htdocs/lara/laravel-dekho-rnd/Modules/User/Database/Migrations/2020_10_19_115831_create_permissions_table.php
E:\xampp\htdocs\lara\laravel-dekho-rnd>php artisan module:make-migration create_users_permissions_table User
Created : E:/xampp/htdocs/lara/laravel-dekho-rnd/Modules/User/Database/Migrations/2020_10_19_115927_create_users_permissions_table.php
E:\xampp\htdocs\lara\laravel-dekho-rnd>php artisan module:make-migration create_roles_permissions_table User
Created : E:/xampp/htdocs/lara/laravel-dekho-rnd/Modules/User/Database/Migrations/2020_10_19_120205_create_roles_permissions_table.php
composer require spatie/laravel-permission
----------------------------------------------------
Implement Custom Helper file
----------------------------------------------------
Implement Custom Service Provider:
1. php artisan module:make-provider RiakServiceProvider Article
2. Create files:
a) \app\Library\Services\DemoOne.php
namespace App\Library\Services;
use App\Library\Services\Contracts\CustomServiceInterface;
class DemoOne implements CustomServiceInterface
{
public function doSomethingUseful()
{
return 'Output from DemoOne';
}
}
b) \app\Library\Services\DemoTwo.php
namespace App\Library\Services;
use App\Library\Services\Contracts\CustomServiceInterface;
class DemoTwo implements CustomServiceInterface
{
public function doSomethingUseful()
{
return 'Output from DemoTwo';
}
}
c) \app\Library\Services\Contracts\CustomServiceInterface.php
namespace App\Library\Services\Contracts;
Interface CustomServiceInterface
{
public function doSomethingUseful();
}
3. Open config\app.php
'providers' => [
...
Modules\Article\Providers\RiakServiceProvider::class,
]
4. Open file Modules/Article/Providers/RiakServiceProvider.php
use App\Library\Services\DemoOne;
public function register()
{
$this->app->bind('App\Library\Services\Contracts\CustomServiceInterface', function ($app) {
return new DemoOne();
});
}
5. Open Controller (ArticleController)
use App\Library\Services\Contracts\CustomServiceInterface;
public function testServiceProvider(CustomServiceInterface $customServiceInstance)
{
echo $customServiceInstance->doSomethingUseful();
return view('article::testServiceProvider');
}
---------------------------------------------------
Implement Localisation - locale
1. Create files: \Resources\lang\en\lang.php and \Resources\lang\hi\lang.php
<?php
return [
'msg' => 'Laravel Internationalization example of english.'
];
?>
2. Open controller file and add function
public function localisation(Request $request,$locale) {
//set's application's locale
app()->setLocale($locale);
//Gets the translated message and displays it
echo trans('article::lang.msg');
}
3. Create router file:
Route::get('/localisation/{locale}', 'ArticleController@localisation');
-----------------------------------------------------
Two way authentication: status=pending
composer require pragmarx/google2fa-laravel
php artisan vendor:publish --provider=PragmaRX\\Google2FALaravel\\ServiceProvider
----------------------------------------------------
QR Code generator:
https://kerneldev.com/qr-codes-in-laravel-complete-guide/
1. composer require simplesoftwareio/simple-qrcode
2. composer dumpautoload
3. a) Route::get('qr-code', function () {
return QrCode::size(500)->generate('Welcome to kerneldev.com!');
});
b) Route::get('qr-code', function () {
$pngImage = QrCode::format('png')->merge('ss.png', 0.3, true)
->size(500)->errorCorrection('H')
->generate('Welcome to kerneldev.com!');
return response($pngImage)->header('Content-type','image/png');
});
c) //Specify email address, subject and the body
QrCode::email('qrcode@localhost.com', 'Thank you for the QR code tutorial.', 'This was awesome!.');
//Specify subject and the body, let user enter the to_address
QrCode::email(null, 'Hi there.', 'This is the message body.');
//Specify just email address
QrCode::email('sapnesh@kerneldev.com');
d) QrCode::phoneNumber($number);
QrCode::phoneNumber('776-004-1698');
QrCode::SMS($number, $message);
QrCode::geo($latitude, $longitude);
e) QrCode::wiFi([
'encryption' => 'WPA/WEP',
'ssid' => 'SSID of the network',
'password' => 'Password of the network',
'hidden' => 'Whether the network is a hidden SSID or not.'
]);
4. in .blade.php file:
a) {!! QrCode::generate('Welcome to kerneldev.com!'); !!}
b) {!! base64_encode(QrCode::format('png')->merge('ss.png', 0.3, true)
->size(500)->errorCorrection('H')
->generate('Welcome to kerneldev.com!')) !!} ">
-----------------------------------------------------
Razorpay Payment Gateway Integration:
1. Install: composer require razorpay/razorpay
2. add razorkey and razorsecret in .env file:
RAZOR_KEY=your_razorpay_key
RAZOR_SECRET=your_razorpay_secret
3. php artisan module:make-controller PaymentController ShoppingCart
-------------------------------------------------------
How to create database seeder:
1. php artisan module:make-seed seed_fake_blog_posts Blog //Generate the given seed name for the specified module.
2. php artisan module:seed AclManage //insert dummy data available in /database/seeders folder
#################################################################################
E:\xampp\htdocs\lara\quickstart>composer require nwidart/laravel-modules
Using version ^7.2 for nwidart/laravel-modules
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Installing nwidart/laravel-modules (7.2.0): Downloading (100%)
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fideloper/proxy
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Discovered Package: nwidart/laravel-modules
Package manifest generated successfully.
73 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
E:\xampp\htdocs\lara\quickstart>php artisan module:make Role Contactus Tutorial
Created : E:\xampp\htdocs\lara\quickstart\Modules/Role/module.json
Created : E:\xampp\htdocs\lara\quickstart\Modules/Role/Routes/web.php
Created : E:\xampp\htdocs\lara\quickstart\Modules/Role/Routes/api.php
Created : E:\xampp\htdocs\lara\quickstart\Modules/Role/Resources/views/index.blade.php
Created : E:\xampp\htdocs\lara\quickstart\Modules/Role/Resources/views/layouts/master.blade.php
Created : E:\xampp\htdocs\lara\quickstart\Modules/Role/Config/config.php
Created : E:\xampp\htdocs\lara\quickstart\Modules/Role/composer.json
Created : E:\xampp\htdocs\lara\quickstart\Modules/Role/Resources/assets/js/app.js
Created : E:\xampp\htdocs\lara\quickstart\Modules/Role/Resources/assets/sass/app.scss
Created : E:\xampp\htdocs\lara\quickstart\Modules/Role/webpack.mix.js
Created : E:\xampp\htdocs\lara\quickstart\Modules/Role/package.json
Created : E:/xampp/htdocs/lara/quickstart/Modules/Role/Database/Seeders/RoleDatabaseSeeder.php
Created : E:/xampp/htdocs/lara/quickstart/Modules/Role/Providers/RoleServiceProvider.php
Created : E:/xampp/htdocs/lara/quickstart/Modules/Role/Providers/RouteServiceProvider.php
Created : E:/xampp/htdocs/lara/quickstart/Modules/Role/Http/Controllers/RoleController.php
Module [Role] created successfully.
Created : E:\xampp\htdocs\lara\quickstart\Modules/Contactus/module.json
Created : E:\xampp\htdocs\lara\quickstart\Modules/Contactus/Routes/web.php
Created : E:\xampp\htdocs\lara\quickstart\Modules/Contactus/Routes/api.php
Created : E:\xampp\htdocs\lara\quickstart\Modules/Contactus/Resources/views/index.blade.php
Created : E:\xampp\htdocs\lara\quickstart\Modules/Contactus/Resources/views/layouts/master.blade.php
Created : E:\xampp\htdocs\lara\quickstart\Modules/Contactus/Config/config.php
Created : E:\xampp\htdocs\lara\quickstart\Modules/Contactus/composer.json
Created : E:\xampp\htdocs\lara\quickstart\Modules/Contactus/Resources/assets/js/app.js
Created : E:\xampp\htdocs\lara\quickstart\Modules/Contactus/Resources/assets/sass/app.scss
Created : E:\xampp\htdocs\lara\quickstart\Modules/Contactus/webpack.mix.js
Created : E:\xampp\htdocs\lara\quickstart\Modules/Contactus/package.json
Created : E:/xampp/htdocs/lara/quickstart/Modules/Contactus/Database/Seeders/ContactusDatabaseSeeder.php
Created : E:/xampp/htdocs/lara/quickstart/Modules/Contactus/Providers/ContactusServiceProvider.php
Created : E:/xampp/htdocs/lara/quickstart/Modules/Contactus/Providers/RouteServiceProvider.php
Created : E:/xampp/htdocs/lara/quickstart/Modules/Contactus/Http/Controllers/ContactusController.php
Module [Contactus] created successfully.
Created : E:\xampp\htdocs\lara\quickstart\Modules/Tutorial/module.json
Created : E:\xampp\htdocs\lara\quickstart\Modules/Tutorial/Routes/web.php
Created : E:\xampp\htdocs\lara\quickstart\Modules/Tutorial/Routes/api.php
Created : E:\xampp\htdocs\lara\quickstart\Modules/Tutorial/Resources/views/index.blade.php
Created : E:\xampp\htdocs\lara\quickstart\Modules/Tutorial/Resources/views/layouts/master.blade.php
Created : E:\xampp\htdocs\lara\quickstart\Modules/Tutorial/Config/config.php
Created : E:\xampp\htdocs\lara\quickstart\Modules/Tutorial/composer.json
Created : E:\xampp\htdocs\lara\quickstart\Modules/Tutorial/Resources/assets/js/app.js
Created : E:\xampp\htdocs\lara\quickstart\Modules/Tutorial/Resources/assets/sass/app.scss
Created : E:\xampp\htdocs\lara\quickstart\Modules/Tutorial/webpack.mix.js
Created : E:\xampp\htdocs\lara\quickstart\Modules/Tutorial/package.json
Created : E:/xampp/htdocs/lara/quickstart/Modules/Tutorial/Database/Seeders/TutorialDatabaseSeeder.php
Created : E:/xampp/htdocs/lara/quickstart/Modules/Tutorial/Providers/TutorialServiceProvider.php
Created : E:/xampp/htdocs/lara/quickstart/Modules/Tutorial/Providers/RouteServiceProvider.php
Created : E:/xampp/htdocs/lara/quickstart/Modules/Tutorial/Http/Controllers/TutorialController.php
/////////////////////////////////////////////////////////////////////////////////////////////////////
Creating Migration in a Module
URL: https://medium.com/@destinyajax/how-to-build-modular-applications-in-lar...
///////////////////////////////////////////////////////////////////////////////////////////////////