Practical Laravel: Develop clean MVC web applications by Vallejo Paola & Correa Daniel
Author:Vallejo, Paola & Correa, Daniel
Language: eng
Format: epub
Published: 2022-02-12T00:00:00+00:00
$newProduct = new Product();
$newProduct->setName($request->input('name'));
$newProduct->setDescription($request->input('description'));
$newProduct->setPrice($request->input('price'));
$newProduct->setImage("game.png");
$newProduct->save();
Next, we create a newProduct instance. Then, we set the newProduct attributes based on values collected from the form. We use the request->input method to retrieve the form inputs. We also set a default image (game.png). In the end, we invoke the save method, which inserts the object data into the database. The model's created_at and updated_at timestamps will automatically be set when the save method is called, so there is no need to set them manually.
Note: setting one by one each model attribute presents an issue. When a model has many attributes, it implies manually calling several setters. We will see an alternative at the end of this chapter.
Analyze Code
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Content Management | Programming |
User Experience & Usability | User Generated Content |
Web Design | Web Marketing |
Web Services | Website Analytics |
Hello! Python by Anthony Briggs(9916)
The Mikado Method by Ola Ellnestam Daniel Brolund(9779)
Dependency Injection in .NET by Mark Seemann(9340)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7783)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Svelte with Test-Driven Development by Daniel Irvine(7188)
Test-Driven Development with PHP 8 by Rainier Sarabia(6913)
Layered Design for Ruby on Rails Applications by Dementyev Vladimir;(6781)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(6536)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6419)
Web Development with Django by Ben Shaw Saurabh Badhwar(6246)
React Application Architecture for Production by Alan Alickovic(5971)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(5807)
Kotlin in Action by Dmitry Jemerov(5066)
Audition by Ryu Murakami(4583)
Software Architecture for Web Developers by Mihaela Roxana Ghidersa(4462)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4318)
Accelerating Server-Side Development with Fastify by Manuel Spigolon Maksim Sinik & Matteo Collina(4311)
Functional Programming in JavaScript by Mantyla Dan(4038)
