Home >Database >Mysql Tutorial >Laravel 5: Why is My \'Table Not Found\' Error Happening and How Do I Fix It?
Base Table Not Found: Troubleshooting in Laravel 5
When attempting to save data to MySQL using Laravel 5, an "1146 Table not found" error can occur. This issue arises when Laravel cannot determine the plural form of a table name, resulting in the addition of an "S" to the end of the name.
Controller and Model Configuration
Here's the provided controller store method:
<code class="php">public function store(CotFormRequest $request) { $quote = new Cotizacion; $quote->customer_id = Input::get('data.clientid'); $quote->total = Input::get('data.totalAftertax'); $quote->save(); }</code>
And the model Cotizacion:
<code class="php">namespace App\Models\Cotizacion; use Illuminate\Database\Eloquent\Model; class Cotizacion extends Model { }</code>
Resolving the Issue
To fix this, explicitly define the table name in the model:
<code class="php">class Cotizacion extends Model{ public $table = "cotizacion"; }</code>
By specifying the table name, Laravel will correctly identify it and prevent adding an extra "S".
The above is the detailed content of Laravel 5: Why is My \'Table Not Found\' Error Happening and How Do I Fix It?. For more information, please follow other related articles on the PHP Chinese website!