Laravel 5.3 Routes are not working - boilerpate repo - php

I am using latest repo of laravelboilerplate i got this error on server. but it works fine on homestead.
I try to user clear:cache but its the same.
UnexpectedValueException in Route.php line 646:
Invalid route action: [App\Http\Controllers\Backend\Takeaway\addOnCategory\AddOnCategoryTableController]
and here is the code in controller
<code>
namespace App\Http\Controllers\Backend\Takeaway\AddOnCategory;
use App\Http\Controllers\Controller;
use App\Repositories\Backend\Takeaway\AddOnCategory\AddOnCategoryRepository;
use Yajra\Datatables\Facades\Datatables;
use App\Http\Requests\Request;
/**
* Class UserTableController
*/
class AddOnCategoryTableController extends Controller
{
/**
* #var UserRepository
*/
protected $addOnCategory;
/**
* #param UserRepository $users
*/
public function __construct(AddOnCategoryRepository $addOnCategory)
{
$this->addOnCategory = $addOnCategory;
}
/**
* #param ManageUserRequest $request
* #return mixed
*/
public function __invoke() {
return Datatables::of($this->addOnCategory->getForDataTable())
->addColumn('actions', function($addOnCategory) {
return $addOnCategory->action_buttons;
})
->make(true);
}
}
and here is the code in route
<code>
Route::group([
'prefix' => 'takeaway',
'as' => 'takeaway.',
'namespace' => 'Takeaway\addOnCategory',
], function() {
/**
* Settings Specific Functionality
*/
/**
* User CRUD
*/
Route::resource('/addOnCategory', 'AddOnCategoryController');
Route::get('addOnCat/get', 'AddOnCategoryTableController')->name('addOnCategory.get');
});

You need to provide the name of your method with AddOnCategoryTableController
Just try like this
Route::get('addOnCat/get', 'AddOnCategoryTableController#__invoke')->name('addOnCategory.get');

Related

Query Parameters not working when default api prefix is changed to something else

I am using Laravel 7.0.
I have created a new module and in the new modules RouteServiceProvider.php file changed the prefix of the API routes to cp.
I am now trying to send some query parameters but nothing is received in the controller action method.
Here you can see the Laravel Telescope also not showing any query parameters. I checked the Nginx logs and query parameters are present there.
php artisan route:list is showing the route correctly.
Here is the code of the controller.
<?php
namespace Modules\SomeModule\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
class PartnerController extends Controller
{
/**
* List all Partners
*
* #param Illuminate\Http\Request $request
* #return \Illuminate\Http\JsonResponse
*/
public function index(Request $request)
{
$page = $request->query('page'); // it is always null
$pageSize = $request->query('page_size'); // it is always null
return response()->json(['page' => $page, 'page_size' => $pageSize]);
}
}
Here is the code of RouteServiceProvider. I am using nWidart/laravel-modules package to generate modules in my app.
<?php
namespace Modules\SomeModule\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
/**
* The module namespace to assume when generating URLs to actions.
*
* #var string
*/
protected $moduleNamespace = 'Modules\SomeModule\Http\Controllers';
/**
* Called before routes are registered.
*
* Register any model bindings or pattern based filters.
*
* #return void
*/
public function boot()
{
parent::boot();
}
/**
* Define the routes for the application.
*
* #return void
*/
public function map()
{
$this->mapApiRoutes();
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*
* #return void
*/
protected function mapApiRoutes()
{
Route::middleware('api')
->prefix('cp')
->namespace($this->moduleNamespace)
->group(module_path('SomeModule', '/Routes/api.php'));
}
}
When I changed the API prefix back to api it works absolutely fine.
Can someone please guide what is going on here? Thanks!

Laravel route middleware outputting my log

I'm trying to run some middleware on my routes via my package's service provider before the routes run in my Laravel project but I'm not seeing my var_dump despite running php artisan route:list showing that the BeforeMiddleware is applied. Am I using the wrong middleware?
My service provider:
<?php
namespace Company\FudgeInboundManagementBridge;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use Company\FudgeInboundManagementBridge\Http\Middleware\BeforeMiddleware;
class FudgeInboundManagementBridgeServiceProvider extends ServiceProvider
{
/**
* Bootstrap services.
*
* #return void
*/
public function boot()
{
$this->registerFiles();
}
/**
* Register files
*/
protected function registerFiles(): void
{
Route::middleware(BeforeMiddleware::class)->group(function () {
$this->loadRoutesFrom(__DIR__.'/routes/fudge-routes.php');
});
$this->publishes([
__DIR__ . '/config/FudgeInboundManagementBridge.php' => config_path('FudgeInboundManagementBridge.php'),
], 'config');
}
}
My middleware:
<?php
namespace Company\FudgeInboundManagementBridge\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class BeforeMiddleware
{
/**
* Handle an incoming request.
*
* #param \Illuminate\Http\Request $request
* #param \Closure $next
* #return mixed
*/
public function handle(Request $request, Closure $next)
{
var_dump('hello from before middleware - bridge');
die;
// return $next($request);
}
}
Seems like it's not triggering?

Laravel 5.6 - Seeder Class not found

I'm trying to populate a Laravel 5.6 project DB - following the offial docs - without success. php artisan db:seed throws this exception:
Symfony\Component\Debug\Exception\FatalThrowableError : Class 'App\Item' not found
at /Applications/MAMP/htdocs/greylab/inventario/greylab_inventario/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:217
Exception trace:
1 Illuminate\Database\Eloquent\FactoryBuilder::make([])
/Applications/MAMP/htdocs/greylab/inventario/greylab_inventario/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:167
2 Illuminate\Database\Eloquent\FactoryBuilder::create()
/Applications/MAMP/htdocs/greylab/inventario/greylab_inventario/database/seeds/ItemTableSeeder.php:14
I already tried most of the common suggestions provided from the community, like this one, as well as:
Trying with composer self-update + composer dump-autoload;
On my composer.json the autoload property is set as is:
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/"
}
},
(Tried to put classmap in autoload-dev too).
Here's the situation:
ItemFactory.php
<?php
use Faker\Generator as Faker;
// Definizione dati test
$factory->define(App\Item::class, function (Faker $faker) {
return [ ...]
}
ItemTableSeeder.php
<?php
use Illuminate\Database\Seeder;
class ItemTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* #return void
*/
public function run()
{
factory(App\Item::class, 25)->create();
}
}
DatabaseSeeder.php
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* #return void
*/
public function run()
{
$this->call(ItemTableSeeder::class);
}
}
At last, I tried to put dependencies directly in sources too:
use App\Item;
use Illuminate\Database\Seeder;
by removing the App\ prefix and leave only Item::class in the argument:
factory(Item::class, 25)->create();
All these tries didn't helped, so I'm actually stuck.
If anyone could show me the way, it should be really appreciated.
Thanks in advance to all.
UPDATE
#kerbholz & #h-h: There was a mistyped trait in ItemTableSeeder.php, thanks for both your suggestion. Yes, in first place I implemented an Item.php model like this:
<?php
// Definizione Namespace
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Classe Item
*/
class Item extends Model
{
use SoftDeletes;
// Dichiarazione Proprietà
protected $table = 'item';
protected $dateformat = 'Y-m-d';
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'data_acquisto',
'labeled',
'estensione_garanzia',
'stato',
'data_dismissione',
'note'
];
/**
* The attributes that should be hidden for arrays.
*
* #var array
*/
protected $hidden = [
'codice',
'serial',
'componente_id',
'tipologia_id',
'condizione_id',
'locazione_id',
'fornitore_id',
'parent_id'
];
/**
* The attributes that should be mutated to dates.
*
* #var array
*/
protected $dates = [
'data_acquisto',
'data_dismissione',
'deleted_at'
];
/**
* All of the relationships to be touched.
*
* #var array
*/
protected $touches = [
'componenti',
'condizioni',
'fornitori',
'locazioni',
'tipologie'
];
/**
* Scope query item figli
* Getter
* #param array $query Query
* #return array Query
*/
public function scopeFigli($query)
{
return $query->where('parent_id', '!=', null);
}
/**
* Componenti Correlati
* Getter
* #return object Componenti
*/
public function componenti()
{
// Definizione relazione
return $this->belongsTo('App\Componente');
}
/**
* Condizioni Correlate
* Getter
* #return object Condizioni
*/
public function condizioni()
{
// Definizione relazione
return $this->belongsTo('App\Condizione');
}
/**
* Fornitori Correlati
* Getter
* #return object Fornitori
*/
public function fornitori()
{
// Definizione relazione
return $this->belongsTo('App\Fornitore');
}
/**
* Locazioni Correlate
* Getter
* #return object Locazioni
*/
public function locazioni()
{
// Definizione relazione
return $this->belongsTo('App\Locazione');
}
/**
* Tipologie Correlate
* Getter
* #return object Tipologie
*/
public function tipologie()
{
// Definizione relazione
return $this->belongsTo('App\Tipologia');
}
}
Meanwhile I continued to implement others. Now, after correcting the mistype and run again twice a composer dump-autoload seeding started. It populated some tables, but after that thrown a new exception. Here's an extract from last try:
Seeding: ItemTableSeeder
ErrorException : Illegal offset type
at /Applications/MAMP/htdocs/greylab/inventario/greylab_inventario/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:257
253| * #throws \InvalidArgumentException
254| */
255| protected function getRawAttributes(array $attributes = [])
256| {
257| if (! isset($this->definitions[$this->class][$this->name])) {
#h-h: In this case, I tried to put backslash before "App": \App\Item::class with no success. Dunno if it's related to some faker misconfiguration...
Found it.
Inside ItemFactory.php I put a stupid $this as factory parameter, in a relation creation:
$factory->define(App\Item::class, function (Faker $faker) {
[...]
'parent_id' => function() {
return factory($this)->create()->id;
}
}
By changing the return sentence in this way:
return factory(App\Item::class)->create()->id;
the issue seems to be solved.
Thanks everyone for the assistance.
You need to either import the Item class like so:
use App\Item;
which means you can do this:
factory(Item::class, 25)->create();
--
Or put a \ before hand like so:
factory(\App\Item::class, 25)->create();
--
Also make sure your Item class has this at the top:
namespace App;
Normally Seeder Class Not Found error occurs, when we have different git branches and we checkout to new branch.
php artisan db:seed --class=StockBranchFileSeeder
Exception: For Target class [StockBranchFileSeeder] does not exist.
Seeder Exception
So I resolved this issue simply run below code in project root;
composer dump-autoload
now Seeder has been successfully executed.

Laravel 5.5 facade not found when using alias

I created a facade.
<?php
namespace VimeoServer\Facades;
use Illuminate\Support\Facades\Facade;
use VimeoServer\App\Repositories\Contracts\VimeoServerRepository;
class Vimeo extends Facade
{
/**
* Get the registered name of the component.
*
* #return string
*/
protected static function getFacadeAccessor()
{
return VimeoServerRepository::class;
}
}
I registered it inside service provider.
/**
* Register the application services.
*
* #return void
*/
public function register()
{
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__ . '/../config/vimeo.php' => config_path('vimeo.php'),
]);
}
$this->app->singleton(VimeoServerRepository::class, function () {
/*
* Config.
*/
$config = config('vimeo.connection');
/*
* Repository.
*/
$repository = new ConcreteVimeoServerRepository($config);
return $repository;
});
}
I registered the service provider:
VimeoServer\App\Providers\VimeoServerServiceProvider::class
and the alias :
'Vimeo' => VimeoServer\Facades\Vimeo::class
I am trying to use it inside Video controller.
If I add use VimeoServer\Facades\Vimeo in the controller everything works as expected.
The problem appears when I try to use the \Vimeo alias, the facade class could not be found.
"message": "Class 'VimeoServer\\Facades\\Vimeo' not found"

Call to undefined method App\Http\Controllers\SubscriptionController::getMiddleware()

I am calling the \prelaunchroute in my application and this is how it is defined in my routes.php:
`Route::get('/prelaunch', [ 'uses' => 'SubscriptionController#getReferrer', 'as' => 'subscriber.referral'], function () {
return view('prelaunch');
});`
But unfortunately, I am getting:
Call to undefined method App\Http\Controllers\SubscriptionController::getMiddleware()
This is a draft of my SubscriptionController code:
namespace App\Http\Controllers;
use App\Http\Manager\SubscriptionManager;
use Illuminate\Support\Facades\Request;
/**
* Class SubscriptionController
* #package App\Http\Controllers
*/
class SubscriptionController
{
/**
* #var \SubscriptionManager $subscriptionManager
*/
protected $subscriptionManager;
/**
* SubscriptionController constructor.
*/
//public function __construct(SubscriptionManager $subscriptionManager)
public function __construct(SubscriptionManager $subscriptionManager)
{
$this->subscriptionManager = $subscriptionManager;
}
/**
* #param Request $request
* #return void
*/
public function subscribe(Request $request)
{
$this->subscriptionManager->subscribeToList($request);
}
/**
* #param Request $request
* #return void
*/
public function unsubscribe(Request $request)
{
$this->subscriptionManager->unsubscribeFromList($request);
}
/**
* #return void
*/
public function getReferrer()
{
print_r(Input::all());
die;
$utm_source = \Input::get('utm_source');
return view('prelaunch');
}
}
Any thoughts on this one? Please bare in mind that I am fairly new to Laravel.
You forgot to extend the abstract controller:
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Http\Manager\SubscriptionManager;
use Illuminate\Support\Facades\Request;
/**
* Class SubscriptionController
* #package App\Http\Controllers
*/
class SubscriptionController extends Controller
Try to extends Controller
/**
* Class SubscriptionController
* #package App\Http\Controllers
*/
class SubscriptionController extends Controller
{

Categories