Laravel 5.3 Passport Models to use NeoEloquent - laravel-5

Is there an easy way to override the Laravel 5.3 Passport Models so they would use Vinelab\NeoEloquent\Eloquent\Model instead of Illuminate\Database\Eloquent\Model

You can give a try and bind it in your service provider in register method:
public function register()
{
$this->app->bind(\Illuminate\Database\Eloquent\Model::class, \Vinelab\NeoEloquent\Eloquent\Model::class)
}

Related

Call to undefined method Laravel\Passport\Passport::routes()

I tried to use Laravel-passport so I installed this package in my project, but when i wanted to make route
i wrote this code in the AuthServiceProvider
public function boot()
{
$this->registerPolicies();
Passport::routes();
}
When i run php artisan route:list in the cmd i face with this error
Call to undefined method Laravel\Passport\Passport::routes()
Since version 11 passport's routes have been moved to a dedicated route file. You can remove the Passport::routes() call from your application's service provider.
If you dont want to use default passport routes. you can disabled the route in register method inside AppServicerProvider
public function register()
{
Passport::ignoreRoutes();
}
and you can copy the default passport routes from vendor laravel\passport\routes\web.php
for more detail about UPGRADE read this https://github.com/laravel/passport/blob/11.x/UPGRADE.md
Remove this comment on this line on your AuthServiceProvider file.
protected $policies = [
'App\Models\Model' => 'App\Policies\ModelPolicy',
];

use $this->authorizeResource in boot() laravel backpack crud package

I need to use policy for crud controller in laravel backpack crud package.
I use :
$this->authorizeResource(Post::class);
and i get this error :
Method
App\Http\Controllers\Admin\PostCrudController::authorizeResource does
not exist.
How should i use Policy (specially resource policy) in laravel backpack crud?
You should be able to do that using Laravel's AuthorizesRequests trait. Generated Backpack CRUD Controllers don't have it by default, since not everybody uses this Laravel feature.
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Requests\MonsterRequest as StoreRequest;
use App\Http\Requests\MonsterRequest as UpdateRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class MonsterCrudController extends CrudController
{
use AuthorizesRequests;
public function setup()
{
// ...

Hot to use custom Request class instead NovaRequest (FormRequest) for creating resuorce in Laravel Nova?

I make:
php artisan make:request DiscoverRequest
I want use DiscoverRequest instead default NovaRequest for create new entity for specific resource.
In Laravel Nova exist unified ResourceStoreController for all resources.
public function handle(CreateResourceRequest $request)
Route::post('/{resource}', 'ResourceStoreController#handle');
I want to override Request only for one resource.
How this can be implemented?
Can you elaborate what you mean by "override Request for only one resource"?
Normally you can just type hint the new Request in the method like this:
<?php
namespace App\Http\Controllers;
use App\Http\Requests\StoreItineraryRequest;
class ResourceStoreController extends Controller
{
public function handle(DiscoverRequest $request) {
...
}
}

Namespaces in Php/Laravel

Suppose some controller like this:
<?php
namespace App\Http\Controller
use Illuminate\Http\Request;
use Validator;
use Auth;
class MemberController extends Controller {
//some code
}
Where do Validator and Auth belong to (so I can see their defintion) and what exactly are they?
I've one more question: here (Laravel 5.6 documentaton) it says
we will use the validate method provided by the
Illuminate\Http\Request object.
and when I check here for more information, there's no validate method!
I'd really appreciate it if anyone can help me with these questions.
Validator and Auth are aliases for the Facades of the same name in Illuminate\Support\Facades. They are a static proxy for an instance of a class. You can read about them in the Laravel docs about Facades.
The aliases for these are configured in config/app.php 'aliases' array.
Laravel 5.6 Docs - Facades
For $request->validate(...):
It is a macro. Macros allow you to add functionality to classes that implement macro functionality at run time.
The Illuminate\Foundation\Providers\FoundationServiceProvider#registerRequestValidation sets this macro on Illuminate\Http\Request to allow for a validate method.
/**
* Register the "validate" macro on the request.
*
* #return void
*/
public function registerRequestValidation()
{
Request::macro('validate', function (array $rules, ...$params) {
return validator()->validate($this->all(), $rules, ...$params);
});
}
For a quick read about macros in Laravel check out my article:
asklagbox blog - Using Macros in Laravel

laravel 5.1 authserviceprovider define a permission

Trying to sort out this new AuthServiceProvider in Laravel 5.1.
<?php
namespace App\Providers;
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
public function boot(GateContract $gate)
{
$this->registerPolicies($gate);
$gate->define('test-permission', function ($user) {
return true;
});
}
In my blade I try
#if (Gate::allows('test-permission'))
hello world.
#endif
I get no love. If I change it to Gate::denies('test-permission') the hello world renders.
Ultimate I want to pull my permissions from my Entrust data to migrate my permissions to a Laravel 5.1 environment.
Laravel will only call your closure if there's a logged-in user.
If there's no logged-in user, Laravel will always deny everything.
If you are logged in, chances are you haven't properly registered the AuthServiceProvider.

Resources