Laravel 5.5. InClassLoader.php line 444 - laravel

I am using laravel 5.5 and am trying to make UsersContoller with this command.
php artisan make: controller UsersController --resource --model= User.
My error says:
include(C:\xampp\htdocs\My_laravel\vendor\composer....\app\User.php): failed to open stream: No scuh file or directory

See this video: http://youtu.be/AjQ5e9TOZVk?t=1m45s You can do php artisan list to view all commands, The command for generating REST-ful controllers is controller:make You can view the usage with: php artisan help controller:make
make:command => Create a new command class
make:console => Create a new Artisan command
make:controller => Create a new resource controller class
make:event => Create a new event class
make:middleware => Create a new middleware class
make:migration => Create a new migration file
make:model => Create a new Eloquent model class
make:provider => Create a new service provider class
make:request => Create a new form request class

Related

Laravel: how to simplify artisan commands?

I want to simplify the following artisan commands because I have several databases and the migrations for each database are stored in a separate folder.
php artisan make:migration {{name}} --path=/database/migrations/{{folder}}
php artisan migrate:rollback --path=/database/migrations/{{folder}}
to
php artisan make:migration {{name}} {{folder}}
php artisan migrate:rollback {{folder}}
Is this possible and if so how can I implement it?
Since this is not an option in the Laravel commands, a way to implement this yourself is by writing you own commands that call other artisan commands.
To do so, in your terminal write, for example, php artisan make:command MigrateWithPath to create a new command at app/Console/Commands/MigrateWithPath.php. Then, you can call the vanilla implementation Laravel provides at (vendor\laravel\framework\src) \Illuminate\Database\Console\Migrations\MigrateMakeCommand but then in a way that you specify.
Be sure though that the name of your new command needs to be different from the Laravel one, to prevent recursions. Therefore, I have prefixed the name with app: to be like app:make:migration, but feel free to use something else.
Take a look at the following suggestion:
class MigrateWithPath extends BaseCommand
{
/**
* The name and signature of the console command.
*
* #var string
*/
protected $signature = 'app:make:migration {name : The name of the migration}
{folder? : The location where the migration file should be created}';
/**
* Execute the console command.
*
* #return int
*/
public function handle()
{
$this->call('make:migration', [
'name' => $this->argument('name'),
'--path' => '/database/migrations/' . $this->argument('folder'),
]);
return 0;
}
Then do the same for the rollback command.

Illegal string offset 'name' error calling component from blade

In my Laravel 8 app I created new component with command
php artisan make:component Admin/Auth/loggedUserHasPermissions
and I have error with sending parameter to it from blade file :
Illegal string offset 'name' (View: /mnt/_work_sdb8/wwwroot/lar/AdsBackend8/resources/views/test.blade.php)
On row in resources/views/test.blade.php :
<x-logged-user-has-permissions :logged-user="getLoggedUser()" />
getLoggedUser is funnction in helper file.
and in app/View/Components/Admin/Auth/loggedUserHasPermissions.php
<?php
namespace App\View\Components\Admin\Auth;
use Illuminate\View\Component;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;
class loggedUserHasPermissions extends Component
{
private $loggedUser;
private $hasAdminRole;
public function __construct($loggedUser)
{
$this->loggedUser = $loggedUser;
$this->hasAdminRole = false;
}
public function render()
{
I follow camelCase / kebab-case rules written here https://laravel.com/docs/8.x/blade#passing-data-to-components
running commands
php artisan config:cache
php artisan route:cache
php artisan cache:clear
php artisan view:clear
php artisan clear-compiled
composer dump-autoload
did not help
How it can be fixed?
Thanks!

Why does php artisan migrate fresh --seed is not working properly

Hi developers i have question regarding on php artisan migrate:refresh --seed VS php artisan db:seed I just wanted to ask because I have problem on php artisan migrate:refresh --seed, however when I use the php artisan db::seed it works properly
Now the data that I Created on my seeder is not seeding to the tables. I don't know why where the problem came from
Seeding: VehicleModelsSeeder
Seeded: VehicleModelsSeeder (0 seconds)
Here is my vehicle model seeder class
<?php
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use App\Vehicle;
use App\VehicleModel;
class VehicleModelsSeeder extends Seeder
{
/**
* Run the database seeds.
*
* #return void
*/
public function run()
{
//
$vehicles = Vehicle::all();
foreach($vehicles as $vehicles_data) {
VehicleModel::forceCreate([
'name' => Str::random(5),
'vehicle_id' => $vehicles_data->id
]);
}
}
}
By default, the db:seed command runs the Database\Seeders\DatabaseSeeder class.
There is two solutions:
1. You need to call your additional seeder(s) in the default seeder's run method.
database/seeders/DatabaseSeeder.php
public function run()
{
$this->call([
VehicleModelsSeeder::class
]);
}
Then:
php artisan migrate:refresh --seed
2. You can specify which seeder you want to run with the --class flag, but in this case you need to run the refresh and the migrate commands separately:
php artisan migrate:refresh
php artisan db:seed --class:VehicleModelsSeeder
More info: Laravel database seeding documentation

'php artisan db:seed' doesn't work in Laravel5.4

I have started learning laravel 5.4. In order to populate my db, I complete BreedsTableSeeder.php file.
enter code here
class BreedsTableSeeder extends Seeder {
public function run() {
DB::table('breeds')->insert([
['id' => 1, 'name' => "Domestic"],
['id' => 2, 'name' => "Persian"],
['id' => 3, 'name' => "Siamese"],
['id' => 4, 'name' => "Abyssinian"],
]);
}
}
Then I complete DatabaseSeeder.php.
enter code here
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder {
public function run() {
$this->call(BreedsTableSeeder::class);
}
}
?>
Then, I seed the database by calling it, using the following command.
$ php artisan db:seed
but error occurs as follows
*
[ReflectionException]
Class BreedsTableSeeder does not exist*
When I use,
php artisan db:seed --class="BreedsTableSeeder"
the result is the same.
When I use,
use Illuminate\Database\Eloquent\Model; on DatabaseSeeder.php file
it is automatically deleted.
You need to do
composer dumpautoload
once you create new classes
EDIT
error occurs like this. "Class 'Seeder' not found
Your seeder lacks
use Illuminate\Database\Seeder;
I faced this problem. Now i solved.
And you need to run in your console:
composer dump-autoload
to generate new class map and then run:
php artisan db:seed
I've just tested it. It is working without a problem in Laravel 5

error while trying to run artisan command with Artisan Facade

here's the code
Route::get('run-cmd', function() {
Artisan::call('make:controller HelloController');
});
and I wonder I'm getting this error...
InvalidArgumentException in Application.php line 549:
Command "make:controller HelloController" is not defined.
Did you mean one of these?
make:migration
make:controller
make:middleware
make:request
make:provider
make:console
make:event
make:model
make:command
what's wrong?
Replace
Artisan::call('make:controller HelloController');
with
Artisan::call('make:controller', [ 'name' => 'HelloController' ]);

Resources