Skip to content

Commit 433dddb

Browse files
authored
Update first-app.md
1 parent fc6c8cb commit 433dddb

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

docs/tutorial/first-app.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ class AuthController extends Controller{
188188
189189
//for now, we can just save the title and the body. Later on, we'll save the user_id too
190190
$post = Post::create([
191-
'title' => $request->getParam('first_name'),
192-
'body' => $request->getParam('last_name')
191+
'title' => $request->getParam('title'),
192+
'body' => $request->getParam('body')
193193
]);
194194
195195
$this->flash->addMessage('success', 'New post added successfully'); //You can also use error, info, warning
@@ -224,8 +224,8 @@ class AuthController extends Controller{
224224
225225
//for now, we can just save the title and the body. Later on, we'll save the user_id too
226226
$post = Post::create([
227-
'title' => $request->getParam('first_name'),
228-
'body' => $request->getParam('last_name')
227+
'title' => $request->getParam('title'),
228+
'body' => $request->getParam('body')
229229
]);
230230
231231
$this->flash->addMessage('success', 'New post added successfully'); //You can also use error, info, warning
@@ -237,6 +237,20 @@ class AuthController extends Controller{
237237
return $this->view->render($response,'posts/edit.twig');
238238
239239
}
240+
241+
/**
242+
* Delete post
243+
*
244+
*/
245+
public function delete($request , $response){
246+
//find the post
247+
$post = Post::find($request->getParam('id'));
248+
//delete it
249+
if($post->delete()){
250+
$this->flash->addMessage('success', 'Post deleted successfully');
251+
return $response->withRedirect($this->router->pathFor('posts.index'));
252+
}
253+
}
240254
}
241255
```
242256
Read more about how to perform different kinds of queries using (Laravel's ORM](https://laravel.com/docs/5.3/eloquent) OR (CakePHP's ORM](https://book.cakephp.org/3.0/en/orm.html)

0 commit comments

Comments
 (0)