Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Im getting this error when I try to save data to mysql using Laravel 5, other forms and save() methods work fine but this one:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'sistemal5.cotizacions' doesn't exist (SQL: insert into `cotizacions` (`customer_id`, `total`, `updated_at`, `created_at`) values (1501, 150.69, 2015-05-11 03:16:25, 2015-05-11 03:16:25))

Here is my Controller store method:

public function store(CotFormRequest $request)
    {    
        $quote = new Cotizacion;
        $quote->customer_id = Input::get('data.clientid');
        $quote->total = Input::get('data.totalAftertax');    
        $quote->save();    
    }

And here is my model:

<?php namespace AppModelsCotizacion;

use IlluminateDatabaseEloquentModel;


class Cotizacion extends Model {

}

I must be overlooking something really obvious cause i cant understand why Laravel is adding an "S" the table is cotizacion not cotizacions.

How can i troubleshoot this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
276 views
Welcome To Ask or Share your Answers For Others

1 Answer

I'm guessing Laravel can't determine the plural form of the word you used for your table name.

Just specify your table in the model as such:

class Cotizacion extends Model{
    public $table = "cotizacion";

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...