Skip to content

Commit 56661ad

Browse files
author
Jhonny Cohen iMac
committed
CRUD Books Laravel App, added Forms (HTML from Collective)
1 parent 58d1127 commit 56661ad

23 files changed

+1969
-254
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
APP_ENV=local
22
APP_DEBUG=true
33
APP_KEY=SomeRandomString
4-
APP_URL=http://localhost
4+
APP_URL=http://dev.admin
55

66
DB_CONNECTION=mysql
77
DB_HOST=127.0.0.1

.idea/blade.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/copyright/profiles_settings.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/deployment.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/laravel-jwt-admin.iml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 909 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/Http/Controllers/BookController.php

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
use App\Book;
1010
use View;
11+
use Session;
12+
use Redirect;
1113

1214
class BookController extends Controller
1315
{
@@ -43,19 +45,36 @@ public function create()
4345
*
4446
* @return Response
4547
*/
46-
public function store()
48+
public function store(Request $request)
4749
{
50+
$this->validate($request, [
51+
'title' => 'required|max:255',
52+
'author_name' => 'required',
53+
]);
4854
$book = new Book;
4955

50-
$book->title = Input::get('title');
51-
$book->author_name = Input::get('author_name');
52-
$book->pages_count = Hash::make(Input::get('pages_count'));
56+
$book->title = $request->title;
57+
$book->author_name = $request->author_name;
58+
$book->pages_count = $request->pages_count;
5359

5460
$book->save();
5561

62+
Session::flash('flash_message', 'Task successfully added!');
63+
64+
5665
return Redirect::to('/books');
5766
}
5867

68+
69+
public function show($id)
70+
{
71+
$book = Book::findOrFail($id);
72+
73+
return View::make('books.show', [ 'book' => $book ]);
74+
75+
}
76+
77+
5978
/**
6079
* Show the form for editing the specified Book.
6180
*
@@ -64,9 +83,9 @@ public function store()
6483
*/
6584
public function edit($id)
6685
{
67-
$book = Book::find($id);
86+
$book = Book::findOrFail($id);
6887

69-
return View::make('books.edit', [ 'book' => $Book ]);
88+
return View::make('books.edit', [ 'book' => $book ]);
7089
}
7190

7291
/**
@@ -75,15 +94,20 @@ public function edit($id)
7594
* @param int $id
7695
* @return Response
7796
*/
78-
public function update($id)
97+
public function update($id, Request $request)
7998
{
80-
$book = Book::find($id);
99+
$book = Book::findOrFail($id);
81100

82-
$book->title = Input::get('title');
83-
$book->author_name = Input::get('author_name');
84-
$book->pages_count = Hash::make(Input::get('pages_count'));
101+
$this->validate($request, [
102+
'title' => 'required',
103+
'author_name' => 'required'
104+
]);
85105

86-
$book->save();
106+
$input = $request->all();
107+
108+
$book->fill($input)->save();
109+
110+
Session::flash('flash_message', 'Book successfully Edited!');
87111

88112
return Redirect::to('/books');
89113
}

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
"laravel/framework": "5.2.*",
1010
"dingo/api": "1.0.x@dev",
1111
"barryvdh/laravel-cors": "^0.8.0",
12-
"tymon/jwt-auth": "0.5.*"
12+
"tymon/jwt-auth": "0.5.*",
13+
"mpociot/laravel-apidoc-generator": "^1.4",
14+
"laravelcollective/html": "5.2.*"
15+
1316
},
1417
"require-dev": {
1518
"fzaninotto/faker": "~1.4",

0 commit comments

Comments
 (0)