I'm new to Lumen (ver. 8.3.4) and I got a strange issue during my tests.
In my DB I have the table "Pippo"; to query it I created the model App\Models\Pippo and the controller App\Http\Controllers\PippoController.php, that includes the aforementioned model.
To route the requests, in web.php I added the line:
$router->post('getdomain', 'PippoController#getdomain');
Now, in 'getdomain' function I've a simple
$var = Pippo::all();
but when I try to call it, I get the following error:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'authserver.pippos' doesn't exist (SQL: select * from pippos)
I searched and researched multiple times in the code, but I don't understand why Lumen adds the 's' character to the table name.
Any suggestion?
you can put in modal protected $table = 'pippo'; To avoid this error
Related
See this issues below , I having this issue.After creating a Model Like Burgers PHP
My Front Welcome page is working properly but when I go threw 127.0.0.1:8000/burgers
this address it's error below .
here is the error message :
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'backyardburger.burgers' doesn't exist (SQL: select * from `burgers`) ```
Rename your table to burgers
OR
add the following to your Burger.php
protected $table = 'backyardburger';
I'm using spatie/laravel-menu and spatie/laravel-persmissions in my laravel project.
I have created a permission, assigned it to a role, and assigned the role to my user. This works fine.
Then I have generated a menu the middleware way using a macro like so:
\Menu::macro('main', function () use ($request) {
return \Menu::new()
->withoutWrapperTag()
->withoutParentTag()
->setActiveClassOnLink()
->route('preparation', 'Anstehende Termine')
->route('postprocessing', 'Nachbereitung')
->routeIfCan('administrate', 'protocols', 'Protokolle')
->addItemClass('nav-link')
->setActive($request->url());
});
In my application I have two User models with different connections:
App\User; using connection_a with database db_a and
App\DirectoryA\User; using connection_b with database db_b
In the auth config the first one is defined, and using Auth::user()->can('administrate') works fine, even in the Middleware that defines the menu.
Since I have added the menu item via routeIfCan, I'm getting an error. It tells
Base table or view not found: 1146 Table 'db_b.permissions' doesn't exist (SQL: select permissions.*, model_has_permissions.model_id as pivot_model_id, model_has_permissions.permission_id as pivot_permission_id, model_has_permissions.model_type as pivot_model_type from permissions inner join model_has_permissions on permissions.id = model_has_permissions.permission_id where model_has_permissions.model_id = 1 and model_has_permissions.model_type = App\User)
What is going wrong here? It should use the App\User model. Placing a dd() at the point the framework throws the exception shows me the correct connection...
Please help.
this mean table permissions not exist on your database maybe you forgot to run php artisan migrate after install laravel-permission?
A member of spatie helped to solve the problem:
Under the hood, routeIfCan calls app(Gate::class)->allows($ability, $ablityArguments). I assume Gate behaves slightly different than Auth::user() when it comes to multiple guards.
I don't see much room in routeIfCan to add an additional $guard or $connection argument, so I suggest you use $menu->addIf(Auth::user()->can('administrate'), ...) instead.
how do i define the table to query from without having to migrate the db ? i've tried manual define in my model but it doesn't helps.
Eloquent/Model
class Activity extends Model {
protected $table = 'log_activity';
}
my table supposed to be 'log_activity' but not 'activities' as the exception below
QueryException in Connection.php line 673:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'bizoctopus.activities' doesn't exist (SQL: select * from `activities` where `activities`.`id` = 6 limit 1)
my mistake creating the model file inside sub directory folder named 'providers' instead of app folder.
thanks for the help.. appreciate it
I'm starting to learn Laravel. I've run through the example instructions from the site successfully and now I'm trying a second run through and I'm running into an issue.
I'm trying to connect to a database called zipCodes and has one table called zipCodeDetails.
In my Laravel project I have a model containing the following code:
<?php
class ZipCodeDetails extends Eloquent {}
And in my routes.php file I have the following code:
Route::get('zipCodes', function (){
$zipCodes = ZipCodeDetails::all();
return View::make('zipCodes')->with('zipCodes', $zipCodes);
});
The error I'm running into is when I try to load the URL:
http://localhost:8888/zipCodes
In my browser I'm getting the error code:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'zipcodes.zip_code_details' doesn't exist (SQL: select * from `zip_code_details`)
There's nothing written in my code where I define the database zipCodes as zipcodes or the table zipCodesDetails as zip_code_details. Something in laravel is changing the database and table names.
Does anyone know why this is happening and how I can prevent it? I don't want to just rename the database or table names because while that may get me by in testing it's not a viable solution in practice.
Thanks!
This is the behaviour that uses if no table is being explicitly defined. In your ZipCodeDetails class, you can set the table name that this model will be using.
class ZipCodeDetails extends Eloquent
{
protected $table = 'zipCodesDetails';
}
I am trying to remove a table from CakePHP. All the tables were created with the cake bake function and I have removed the table from all the models. But when I remove the table from the database I get an error message:
Error: Database table channels_offers for model ChannelsOffer was not found.
Notice: If you want to customize this error message, create app/views/errors/missing_table.ctp
So how do I remove a table that was originally baked in?
Well, it appears that you still have a model called ChannelsOffer. You would need to add a property to your ChannelsOffer model. Here's an example
class ChannelsOffer extends AppModel {
// this tells the model not to use a table, alternatively you could supply your
// own table name here.
public $useTable = false;