How to create modular in laravel? - laravel

I want to create a modular to create a controller and a model.
Of course, the model is pre-created.
php artisan module:make-controller Admin\ReportController Report --model=Report
I see this message
The "--model" option does not exist.

I assume you used nWidart Modules, so the answer is you can not use --model option because nWidart Modules doesn't support that option/parameter. You need run another command to create a model, an example:
php artisan module:make-model Report Admin
Report is model name, and Admin is module name
check it out for more module commands

Related

Spatie Laravel Welcome Notification

did someone encounter this problem when trying to configure the welcome notification using Spatie
I don't have any WelcomeNotification Model. do i need to make one?
I suppose you have created a notification in the model folder because you are using $user->notify(new WelcomeNotification($validUntil)). And, you are passing WelcomeNotification model into notify as a parameter instead of a notification class object, which causes error.
You need to create the notification in the app/Notifications. So, when you run this command it will automatically create the WelcomeNotification in the app/Notifications folder.
php artisan make:notification WelcomeNotification
Now, import use App\Notifications\WelcomeNotification; in the User model.

Change default directory for creating migration in Laravel

I want to change the default directory for creating migration i.e. If I do php artisan make:migration create_users_table, it should create users table in /database/migrations/child_database. I do not want to use --path every time I create a migration for child_database. I want to change the default directory for php artisan make:migration.
you can create your own artisan command to achieve this:
create your a new artisan command and use it to make migration in your custom directory using this article. hope help you ^_^
try this package github repo or use laracast link
You can use loadMigrationsFrom() in your AppServiceProvider.
Inside the boot() function, run:
/**
* Register Custom Migration Paths
*/
$this->loadMigrationsFrom([
database_path().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR.'folder1',
database_path().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR.'folder2',
]);/
This question has been answered before, even though it's a little bit old it still has it's value.
Have a look at: https://stackoverflow.com/a/35895106
If you use this answer, the default directory is changed and you will have the solution you want.

Laravel create Model and Migration dynamically with dynamic table columns

Working on a task where we need to create Model and Migration files programmatically. Also in the Model there will be some predefined functions. These functions will be same for all models. The functions are just relations with other Models. I have searched for a few options and found that Laravel has Stubs and we can create custom stubs which are great but don't think there is any option to pass params to the stub file when generating it.
In this case, we want to create a model and migration with dynamic columns. May be there is no easy way to do it but in case anyone has done it already, can you please provide me a hint of how you did it.
Trying this laravel package
https://github.com/laravel-shift/blueprint
.It can generate models, migrations, controllers from Yaml file. May be we can create a yaml file dynamically and then publish it.
Thanks
you can write your own command.
for example i wrote a command for generate repository pattern in my projects
php artisan make:repository repoName
You can publish stubs
php artisan stub:publish
Create your custom stub
<?php
// stubs/controller.custom.stub
namespace {{ namespace }};
use {{ rootNamespace }}Http\Controllers\Controller;
use Illuminate\Http\Request;
/**
* Hello from the custom controller stub
*/
class {{ class }}
{
//
}
And call it
php artisan make:controller --type=custom MyController
Watch --type option

Laravel Cashier - publish migration results in "cannot declare class CreateCustomersColumns"

I have a fresh Laravel installation and I've added Cashier to my project.
Since the Users model on my app won't have a stripe connection, but rather an Accounts model, I need to alter their migration to add columns to Accounts instead of Users
The documentation says to run:
php artisan vendor:publish --tag="cashier-migrations"
which adds the two migration files to database/migrations
From there I can change users to accounts in the migration file.
When I try to run php artisan migrate, I get:
Whoops\Exception\ErrorException : Cannot declare class CreateCustomerColumns, because the name is already in use
This problem only goes away when I delete the migration files, but then the new columns are added to users.
The documentation states that you can disable their migration files by putting Cashier::ignoreMigrations(); in AppServiceProvider
I didn't realize that's what I wanted to do. I thought the publish command only published the two files I needed to edit, however, those are the only migration files that come with Cashier.
Be sure to add Cashier::ignoreMigrations(); in the register method.
And add use Laravel\Cashier\Cashier;
The file (and thus the class) must exist twice, probably in your database/migrations directory, most likely with 2 different datetime prefixes on the filenames.

How do you extend a view from a package in Laravel?

So i integrated this package to my application, https://github.com/thekordy/ticketit and this package has its own view and i want to modify the views like the create.blade.php,.. how would i do this appropriately?
because my current solutions is just to copy the view from the package change the return view('create'); in my controller?
You will notice many packages include in its instalation proccess this command:
php artisan vendor:publish
What it does behind the scenes is it looks for all package's service providers instructions in order to figure out it anything should be "published" (meaning copying from vendor folder to config/, views/ etc)
I looked at your package's service provider:
https://github.com/thekordy/ticketit/blob/0.2/src/TicketitServiceProvider.php and from line 179 to 182, the package seems to have the correct "publish" instructions.
Which means probably that the documentation skiped this part.
So, you should just basically hit the command php artisan vendor:publish and it will copy views, translations, public and migrations folder to your own apps folders.
Then you will see inside your resources/views a vendor folder, which will now have the ticketit views inside it.
Laravel figure it out when you say "view('ticketit.form.index')" and it will first look inside your own resources folder, if it don't find the content, it will try to look inside the package's folder.
For more, read the docs:https://laravel.com/docs/5.4/packages#views
Just to add one more thing, you can choose which type of resources to publish by using the tags for the publish command
php artisan vendor:publish --provider="Kordy\Ticketit\TicketitServiceProvider" --tag="views"
Publish only ticketit views (destination: base_path/resources/views/vendor/ticketit)
If for any reason, found extending views is not enough and want to extend functionalities or controllers themselves, ticketit allows using of custom routes file, you can use that to point to your own custom controllers.
Other supported vendor publish tags:
php artisan vendor:publish --provider="Kordy\Ticketit\TicketitServiceProvider" --tag="lang"
Publish only ticketit translation files (destination: base_path/resources/lang/vendor/ticketit)
php artisan vendor:publish --provider="Kordy\Ticketit\TicketitServiceProvider" --tag="db"
Publish only ticketit migration files (destination: base_path/database/migrations)
php artisan vendor:publish --provider="Kordy\Ticketit\TicketitServiceProvider" --tag="public"
Publish only ticketit web resources (js, css, ..) files (destination: public_path/vendor/ticketit)
For anyone facing this issue the solution is Laravel default convention, as shown in documentation: https://laravel.com/docs/5.4/packages#views (publishing views topic)
In short, you need to use the resource path as:
'__DIR__.'/path/to/views' => resource_path('views/vendor/view_namespace)'
where view_namespace is the second parameter inside your loadViewsFrom method.
So given the file: https://github.com/thekordy/ticketit/blob/0.2/src/TicketitServiceProvider.php
If line 102 is $this->loadViewsFrom($viewsDirectory, 'ticketit');
Line 103 should be:
$this->publishes([$viewsDirectory => base_path('views/vendor/ticketit')], 'views');

Resources