Skip to content

Instantly share code, notes, and snippets.

@subashz
Created July 19, 2017 16:26
Show Gist options
  • Save subashz/831b950efc0e3fc82c2164a162f82d74 to your computer and use it in GitHub Desktop.
Save subashz/831b950efc0e3fc82c2164a162f82d74 to your computer and use it in GitHub Desktop.
Number of way to save form request in laravel
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