using Laravel 7 and Laratrust 6 and need seeding the Table using the seed command but seeding only some tables only. not seeding following tables as well in the database users,role_user,permission_user
my DataBaseSeeder.php
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
public function run()
{
$this->call(LaratrustSeeder::class);
}
}
how could I fix this problem?
add -> namespace Database\Seeders; in LaratrustSeeder.php in seeder folder
Related
I have a table in my db named affilaite.
But when i try to create a new table named as product it gives me an error
php artisan make:migration create_product_table
PHP Fatal error: Cannot declare class CreateAffiliateTable, because the name is already in use in /home/manak/Desktop/manu/Edolve/database/migrations/2021_03_09_063908_create_affiliate_table.php on line 7
Symfony\Component\ErrorHandler\Error\FatalError
Cannot declare class CreateAffiliateTable, because the name is already in use
at database/migrations/2021_03_09_063908_create_affiliate_table.php:7
3▕ use Illuminate\Database\Migrations\Migration;
4▕ use Illuminate\Database\Schema\Blueprint;
5▕ use Illuminate\Support\Facades\Schema;
6▕
➜ 7▕ class CreateAffiliateTable extends Migration
8▕ {
9▕
10▕ Run the migrations.
11▕
Whoops\Exception\ErrorException
Cannot declare class CreateAffiliateTable, because the name is already in use
at database/migrations/2021_03_09_063908_create_affiliate_table.php:7
3▕ use Illuminate\Database\Migrations\Migration;
4▕ use Illuminate\Database\Schema\Blueprint;
5▕ use Illuminate\Support\Facades\Schema;
6▕
➜ 7▕ class CreateAffiliateTable extends Migration
8▕ {
9▕
10▕ Run the migrations.
11▕
+1 vendor frames
2 [internal]:0
Whoops\Run::handleShutdown()
From This error I Think U already have A migration named CreateAffiliateTable.
Please Change Your Migration name or Delete the Old migration
Check your database/migration folder. if a file already prosent there remove it. Also if there is already a table named exactly the same drop that table from database. Also in database there is a migrations table. Delete the tablename from there also and try migrating again.
By laravel convention migrations are plural and model name singular. So better try CreateAffiliatesTable instead of CreateAffiliateTable
use this command for create
$ php artisan make:migration create_products_table
I have created a model by using the command php artisan make:model Patient. The command creates a model named Patient in the app folder.
In Model Patient:
namespace App;
use Illuminate\Database\Eloquent\Model;
class Patient extends Model
{
//
public function getPurchaseOrder(){
return "Hello World";
}
}
In Controller PatientController:
namespace App\Http\Controllers;
class PatientController extends Controller
{
protected $patientModel;
public function __construct(Request $request, PatientInterface $patient)
{
parent::__construct($request);
$this->patientModel = new \App\Patient();
}
public function test(){
echo $this->patientModel->getPurchaseOrder();
}
}
It's working fine. The problem is when I create a folder named Models inside the app folder and move Patient model then call the model function it gives an error:
FatalThrowableError Class 'App\Models\Patient' not found
Any help will be appreciated.
When you move a class to a different directory, for it to be loaded by composer with the PSR-4 standard, you must also update the class' namespace to match.
namespace App\Models;
In addition, when you run the make command, you can include a namespace in that to automatically put it in the directory with the correct namespace:
php artisan make:model Models\\Patient
I'm a newbie in Laravel5.5, and want to use model in my command ,
first php artisan make:model MyTest, then I use model to get data from mysql.
the command file:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Model\MyTest;
class UboxDataAnalysis extends Command
{
//...
public function handle()
{
$this->line('Then start query');
$o = new App\Model\MyTest();
}
}
And the Model file is:
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use DB;
class MyTest extends Model
{
//
function get_data(){
$uboxTest = DB::connection('mysql-test');
$res = $uboxTest::table('m_user')->where('user_id',166);
var_dump($res);
}
}
But the CLI output is:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'App\Console\Commands\App\Model\MyTest' not found
And I googled and find something about laravel5.5 doc.
To get started, let's create an Eloquent model. Models typically live in the app directory, but you are free to place them anywhere that can be auto-loaded according to your composer.json file.
Is that to say, I need add some config in the composer.json?
Can anybody give me some advice? Thinks.
You've already imported the class with use App\Model\MyTest;, so you can just write $o = new MyTest();.
Instead of that you could remove the import statement and write $o = new \App\Model\MyTest(); (note the added backslash).
I installed spatie/activitylog for logging user activity,
the default table name in this package is activity_log I want change the table name to users_activity_log
I created a model and named Activity but not work:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Models;
class Activity extends Model
{
//
protected $table = "user_activity_log";
}
How can I do it?
I found the solution,
1- Create a model : php artisan make:model Activity
2- put this code in your model (change $table with your table name):
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Activity extends \Spatie\Activitylog\Models\Activity
{
//
protected $table = "user_activity_log";
}
3- publish the logactivity config file:
php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider" --tag="config"
4- change the activity_model in laravel-activitylog.php :
'activity_model' => \App\Activity::class
DON'T FORGET to change table name in migration file
Thanks to #devk
I try to seed a user to the database but cannot. I could easely create the migration tables, so the problem is not in the connection to the database, but I cannot create a user, I get the "Class UsersTableSeeder does not exist" error. How can I solve it? (I use laravel 5.3)
Console Error
Here is my code:
DatabaseSeeder.php
<?php
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class DatabaseSeeder extends Seeder
{
public function run()
{
$this->call(UsersTableSeeder::class);
}
}
UsersTableSeeder.php
<?php
use Illuminate\Database\Seeder;
use App/User;
use Illuminate\Support\Facades\DB;
class UsersTableSeeder extends Seeder
{
public function run()
{
\DB::table('users')->delete();
User::create([
'name' => 'lamin',
'email' => 'lamin#laravel.com',
'password' => bcrypt('lamin')
]);
}
}
Try to run composer dumpauto command and then run seeder again.
Run this command.
composer dump-autoload
It just regenerates the list of all classes that need to be included in the project