Created
July 19, 2017 16:26
-
-
Save subashz/831b950efc0e3fc82c2164a162f82d74 to your computer and use it in GitHub Desktop.
Number of way to save form request in laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function store(Request $request) { | |
$post = new Post; | |
$post->name=$request->name; | |
$post->title = $request->title; | |
$post->tag = $request->tag; | |
$post->save(); | |
} | |
//using request helper method | |
public function store() { | |
$post = new Post; | |
$post->name=request('name'); | |
$post->title = request('title'); | |
$post->tag = request('tag'); | |
$post->save(); | |
} | |
//using create | |
public function store() { | |
Post::create([ | |
'name'=>request('name'), | |
'title'=>request('title'), | |
'tag'=>request('tag') | |
]); | |
} | |
//short and sweet | |
public function store() { | |
Post::create(request(['name','title','tag'])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment