What I am trying to acheive - is create a database seeder for Laravel Notifications. As far as i am using database to store my notifications, there should be a way to achieve it. I am creating Factory model :
$user->notify(new NotificationEvent($event));
In fact it creates a notification in database, but artisan returns with error
[Symfony\Component\Debug\Exception\FatalThrowableError]
Call to undefined method Illuminate\Support\Facades\Notification::save()
Anybody knows what to do?
This seems to be a namespace issue, please try the following, place the class reference on top of your seed class:
use Notification;
Related
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.
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
PhpStorm does not found findOrFail() method. When I try to call it, there isn't auto-complete and the result is always fail. The user found is always on the message.
I try to use Laravel Ide helper and query()->findorfail but I didn't resolve.
The result:
in phpstorm try the Laravel plugin to generate the IDE classes.
please check your User model. It must extend Model class like this.
use Illuminate\Database\Eloquent\Model;
class Lead extends Model {
I guess your User model is missing this "extends Model".
As I know, PHPStorm never detects the findOrFail method even we already installed the Laravel plugin.
But you use it wrong because this method takes an id and returns a single model. If the method can't find any matching data, it will return an error.
You can change the method into:
User::findOrFail($user->id);
Laravel 5.3 with mysql, PHPUnit 5.7.4
When I create a test in PHPUnit with use DatabaseMigrations;, it destroys the data that it queries.
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ThingsTest extends TestCase
{
use DatabaseMigrations;
/** #test */
public function there_are_more_than_1000_things()
{
$things = App\Thing::all();
$this->assertGreaterThan(1000, count($things));
}
Before I run phpunit, there are lots of things. After running it, mysql says ERROR 1146 (42S02): Table 'database.things' doesn't exist
Any ideas how to stop this?
DatabaseMigrations is a trait and it execs:
before test 'php artisan migrate' // creates your tables, but doesn't seed them
after test 'php artisan migrate:rollback' // remove tables
So, 1st - make sure you're using another database for testing.
2nd - seed with fake data your tables before testing your Things class.
Alternative:
use DatabaseTransactions trait instead of DatabaseMigrations.
In that case each test activity will be wrapped in a database transaction. After test all your changes will be dropped by transaction's rollback automatically.
You can be using a test database with PHPUnit within your Laravel application. Right now your tests are using your main database and will modify existing information.
Please see https://stackoverflow.com/a/35228697/823549 for how to do this.
i'm just started to use laravel ide-helper in phpstorm and wanted to document my models.
I've run the command php artisan ide-helper:models but comes up with the error:
'App\Models\Eloquent' not found
After reading it looks as if the error lies in what my models extend - my model class looks like this:
<?php namespace App\Models;
use \Illuminate\Database\Eloquent\Model;
class Article extends Model { }
This is the standard set in the Laravel docs and created by the generators.
Is there a way to resolve this issue so I can generate the docs with the helper or do I leave as is.
Bit confused
Thanks