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!
Related
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
App\Constant\ProductConstant.php
<?php
namespace App\Constant;
use App\Constant\BaseConstant;
class ProductConstant extends BaseConstant {
const TITLE = "title";
}
Product.php
<?php
namespace App\Models;
use App\Constant\ProductConstant;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
protected $table = 'products';
protected $fillable = [ProductConstant::TITLE, ProductConstant::IMAGE, ProductConstant::EXPIRY_DATE, ProductConstant::MAX_PARTICIPANTS, ProductConstant::TOTAL_PARTICIPANTS];
Error
Undefined class constant 'App\Constant\ProductConstant::TITLE'
After I've executed php artisan config:clear. May I know what's the reason?
do not run php artisan config:clear in local system , it may break your project
delete this file bootstrap/cache/config.php
and run project again
run php artisan cache:clear to clear cache of .env file
This is the function
public function waybills()
{
$user = Auth::user();
if(isset($user)){
$uid = $user->id;
$receives = Receive::where('receiver_code', $uid)->with('clearance')->get();
$archives = Archive::where('receiver_code', $uid)->get();
return view("dashboard.receive.waybills", compact('receives', 'archives'));
}
}
and this is the structure of the directory of files
I tried this following artisan codes
php artisan optimize --force
php artisan config:clear
php artisan route:clear
php artisan view:clear
and the error View [dashboard.receive.waybills] not found. persists
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' ]);
I am using the Fullcalendar package for Laravel 5.
I am experiencing this error:
ReflectionException in Container.php line 734:
Class laravel-fullcalendar does not exist
I have the Service Provider and the Facade in app.php.
This is my controller:
namespace App\Http\Controllers\Admin;
use App\Lesson;
use App\Http\Requests;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use MaddHatter\LaravelFullcalendar\Facades\Calendar;
class CalendarController extends Controller
{
public function index()
{
$calendar_events = Lesson::all();
return view('admin.calendar', ['calendar' => Calendar::addEvent($calendar_events)]);
}
}
I don't understand the reason of this error.
I tried to use \Calendar without the "use" line, MaddHatter\LaravelFullcalendar\Facades\Calendar::addEvent() directly and I tried several times composer dump-autoload.
I noticed that I started having the same problem with all the new installed packages.
I resolved in this way:
composer dump-autoload
php artisan cache:clear
php artisan config:clear