php - laravel how to specifiy the input columns -
php - laravel how to specifiy the input columns -
i have form in html has input name restaurantname
, column in database name
. not able utilize in controller
restaurant::create(input::only('restaurantname'));
because there no column restaurantname
question how tell laravel restaurantname
maped name
?
many thanks
editthe html form has these fields:
restaurantname website username password mobilenumber firstname lastname
the database has 2 tables admin
, restaurant
, each restaurant has 1 admin , admin 1 each restaurant, 1 1 relationship
when submit form following:
$input = input::all(); $admin = admin::create(input::only('username', 'password', 'mobilenumber', 'firstname', 'lastname')); $data = ['name' , input::get('restaurantname'), 'website' => input::get('website')]; $restaurant = new restaurant($data); $admin->restaurant()->save($restaurant);
the admin
row inserted database problem starts $data
line code.
the exception is:
badmethodcallexception phone call undefined method illuminate\database\query\builder::save()
firstly, should never blindly pass user input models, , secondly, particular problem has absolutely nil laravel.
your problem can solved basic php. simply, create own array of input.
$data = [ 'field' => input::get('field'), 'name' => input::get('restaurantname') ];
there seems grave misconception laravel own independant system, not. literally collection of php code, doesn't can't done php , doesn't prevent doing can php.
php mysql laravel laravel-4 blade
Comments
Post a Comment