Route:list laravel 5 not changed - laravel-5

It's my first time deploying laravel on shared host.
I have a problem when adding some function on controller that already listed on routes.php.
Everything is ok when I run it on local, but when it's on shared host, and I run php artisan route:list the list doesn't updated
Here's my controller :
public function getIndex(){
return view('content.login');
}
public function postIsLogin(Request $data){
...
}
public function getLogout(){
...
}
And this is my routes.php
Route::controller('/login','LoginController');
Route::controller('/driver','DriverController');
Route::controller('/pushnotif','PushNotificationController');
Route::controller('/','DashboardController');
I add getLogout() function, but when I run php artisan route:list there's no route for getLogout() function.
I appreciate any help. Thank you.

This usually caused by route cache, try to run php artisan route:clear

Related

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!

Laravel Policy not working on route middleware

I have a NotificationPolicy with the following code:
<?php
namespace App\Policies;
use App\Notification;
use App\User;
use Illuminate\Auth\Access\HandlesAuthorization;
class NotificationPolicy
{
use HandlesAuthorization;
public function update(User $user, Notification $notification)
{
return $user->id === $notification->user_id;
}
}
I have registered this properly by adding this to the AuthServiceProvider:
protected $policies = [
Notification::class => NotificationPolicy::class,
];
I have this so that only the logged in user can update their notification by doing things such as setting the archived_at value or read_at value to the current timestamp. The policy does work if I use it in the controller, i.e.;
class ArchiveItemController extends Controller
{
public function __invoke(Notification $notification)
{
$this->authorize('update', $notification);
$notification->markAsArchived();
return redirect()->route('inbox.index')->with('success', 'Item has been archived');
}
}
However I don't want to use them in the controllers and would prefer to use them in my routes file. So I have removed this line $this->authorize('update', $notification); from the controller and I have tried the following but it doesn't work:
Route::prefix('inbox')->middleware(['auth', 'can:employee'])->group(function () {
Route::get('/notification/{notification}/archive', 'User\Account\Inbox\ArchiveItemController')
->name('inbox.item.archive')
->middleware('can:update', 'notification');
});
I've even ran the following but they don't make a difference:
php artisan optimize
php artisan cache:clear
php artisan route:cache
php artisan view:clear
php artisan config:cache
Your middleware declaration is not correct.
You will have to change 'can:update', 'notification' to 'can:update,notification' for it to work:
So in the end you would have the following:
Route::prefix('inbox')->middleware(['auth', 'can:employee'])->group(function () {
Route::get('/notification/{notification}/archive', 'User\Account\Inbox\ArchiveItemController')
->name('inbox.item.archive')
->middleware('can:update,notification');
});
If you have cached the routes, you will have to run php artisan route:clear for the changes to take effect.
From the docs:
Laravel includes a middleware that can authorize actions before the
incoming request even reaches your routes or controllers. By default,
the Illuminate\Auth\Middleware\Authorize middleware is assigned the
can key in your App\Http\Kernel class. Let's explore an example of
using the can middleware to authorize that a user can update a blog
post:
use App\Post;
Route::put('/post/{post}', function (Post $post) {
// The current user may update the post...
})->middleware('can:update,post');
In this example, we're passing the can middleware two arguments. The
first is the name of the action we wish to authorize and the second is
the route parameter we wish to pass to the policy method. In this
case, since we are using implicit model binding, a Post model will be
passed to the policy method. If the user is not authorized to perform
the given action, a HTTP response with a 403 status code will be
generated by the middleware.

Route Model Binding not working Laravel 6

Route Model Binding not working
model: Accommodation
Controller: AccommodationController
Route::resource('accommodation', 'AccommodationController');
Working
public function index()
{
$accommodation = Accommodation::get();
return view('admin.accommodations.index', compact('accommodation'));
}
Not working
public function index(Accommodation $accommodation)
{
return view('admin.accommodations.index', compact('accommodation'));
}
You can see your route list in your php artisan terminal to avoid confusion.Use command.
php artisan route:list
Then see in name list what was name , then put in your route function.
However, I think your route will be
admin.accommodation
remove 's'.

Serialization of 'Closure' is not allowed Laravel routing?

When I launch command: php artisan route:cache I get message:
Serialization of 'Closure' is not allowed
There is only one closure in routes:
Route::group(['middleware' => ['auth']], function () {
})
I use php 7.1
Move the closure in routes/api.php to controller or comment it
// Route::middleware('auth:api')->get('/user', function (Request $request) {
// return $request->user();
// });
Then run
php artisan route:clear
php artisan route:cache
Laravel will try to cache routes by serializing to base64 encoded text in bootstrap/cache/routes.php, and closures can't be serialized

ErrorException running php artisan vendor:publish with Elqouent-Sluggable

I'm using Laravel 5 and attempting to install Eloquent-Sluggable. I have followed all the steps in the installation instructions:
composer require cviebrock/eloquent-sluggable
composer update
Add Cviebrock\EloquentSluggable\SluggableServiceProvider::class to the Providers in config/app.php
php artisan vendor:publish
The last step resulted in this error message:
[ErrorException] Argument 2 passed to
Cviebrock\EloquentSluggable\SluggableTableCommand::__construct() must be an instance of Illuminate\Foundation\Composer, instance of
Illuminate\Support\Composer given, called in
C:\wamp\www\blog\vendor\cvi
ebrock\eloquent-sluggable\src\SluggableServiceProvider.php on line 92 and defined
What caused the error to occur?
It happened to me too. This is because the SluggableTableCommand requires Composer instance in its constructor but accidentally different type of instance is passed.
This might not be the smartest way to fix this but if you are in rush you can just remove the Composer declaration before $composer in the SluggableTableCommand constructor. The file that you need to edit is vendor/cviebrock/eloquent-sluggable/src/SluggableTableCommand.php on line 44
This should work:
/**
* Create a new migration sluggable instance.
*
* #param SluggableMigrationCreator $creator
* #param Composer $composer
*/
public function __construct(
SluggableMigrationCreator $creator,
$composer
) {
parent::__construct();
$this->creator = $creator;
$this->composer = $composer;
}
I had the same error using Laravel 5.2.29 when I tried to create migration via console command
php artisan sluggable:table posts slug
What solved the issue was creation usual Laravel migration, but I had commented 'Cviebrock\EloquentSluggable\SluggableServiceProvider::class' row in config/app.php file before.
php artisan make:migration add_slug_to_posts_table
with the next code in migration file
public function up(){
Schema::table('posts', function(Blueprint $table){
$table->string('slug')->nullable();
});
}
public function down(){
Schema::table('posts', function(Blueprint $table){
$table->dropColumn('slug');
});
}
and ran the migration
php artisan migrate

Resources