3
3
namespace App \Http \Controllers ;
4
4
5
5
use App \City ;
6
- use App \State ;
7
6
use App \Setting ;
7
+ use App \State ;
8
8
use Illuminate \Http \Request ;
9
9
use Illuminate \Support \Facades \Input ;
10
10
@@ -20,6 +20,7 @@ public function __construct()
20
20
$ this ->middleware ('auth ' );
21
21
$ this ->middleware ('role:admin ' );
22
22
}
23
+
23
24
/**
24
25
* Display a listing of the resource.
25
26
*
@@ -28,25 +29,14 @@ public function __construct()
28
29
public function index ()
29
30
{
30
31
$ stateId = Input::get ('state_id ' );
31
- if (!isset ($ stateId )){
32
+ if (!isset ($ stateId )) {
32
33
$ stateId = State::first ()->id ;
33
34
}
34
35
$ state = State::find ($ stateId );
35
36
$ cities = City::where (['state_id ' => $ stateId ])->paginate (Setting::paginacao ());
36
37
return view ('cities.index ' , ['state ' => $ state , 'cities ' => $ cities ]);
37
38
}
38
39
39
- /**
40
- * Show the form for creating a new resource.
41
- *
42
- * @return \Illuminate\Http\Response
43
- */
44
- public function create ()
45
- {
46
- $ states = State::all ();
47
- return view ('cities.form ' , ['city ' => new City (), 'states ' =>$ states ]);
48
- }
49
-
50
40
/**
51
41
* Store a newly created resource in storage.
52
42
*
@@ -55,33 +45,32 @@ public function create()
55
45
*/
56
46
public function store (Request $ request )
57
47
{
58
- if (City::create ($ request ->input ())){
59
- return redirect (route ('cities.index ' ). "?state_id= " . $ request ->state_id );
48
+ if (City::create ($ request ->input ())) {
49
+ return redirect (route ('cities.index ' ) . "?state_id= " . $ request ->state_id );
60
50
} else {
61
51
return $ this ->create ();
62
52
}
63
53
}
64
54
65
55
/**
66
- * Display the specified resource.
56
+ * Show the form for creating a new resource.
67
57
*
68
- * @param \City $city
69
58
* @return \Illuminate\Http\Response
70
59
*/
71
- public function show ( City $ city )
60
+ public function create ( )
72
61
{
62
+ $ states = State::all ();
63
+ return view ('cities.form ' , ['city ' => new City (), 'states ' => $ states ]);
73
64
}
74
65
75
66
/**
76
- * Show the form for editing the specified resource.
67
+ * Display the specified resource.
77
68
*
78
69
* @param \City $city
79
70
* @return \Illuminate\Http\Response
80
71
*/
81
- public function edit (City $ city )
72
+ public function show (City $ city )
82
73
{
83
- $ states = State::all ();
84
- return view ('cities.form ' ,['city ' => $ city , 'states ' =>$ states ]);
85
74
}
86
75
87
76
/**
@@ -93,13 +82,25 @@ public function edit(City $city)
93
82
*/
94
83
public function update (Request $ request , City $ city )
95
84
{
96
- if ($ city ->update ($ request ->input ())){
97
- return redirect (route ('cities.index ' ). "?state_id= " . $ city ->state_id );
85
+ if ($ city ->update ($ request ->input ())) {
86
+ return redirect (route ('cities.index ' ) . "?state_id= " . $ city ->state_id );
98
87
} else {
99
88
return $ this ->edit ($ city );
100
89
}
101
90
}
102
91
92
+ /**
93
+ * Show the form for editing the specified resource.
94
+ *
95
+ * @param \City $city
96
+ * @return \Illuminate\Http\Response
97
+ */
98
+ public function edit (City $ city )
99
+ {
100
+ $ states = State::all ();
101
+ return view ('cities.form ' , ['city ' => $ city , 'states ' => $ states ]);
102
+ }
103
+
103
104
/**
104
105
* Remove the specified resource from storage.
105
106
*
@@ -110,6 +111,6 @@ public function destroy(City $city)
110
111
{
111
112
$ stateId = $ city ->state_id ;
112
113
$ city ->delete ();
113
- return redirect (route ('cities.index ' ). "?state_id= " . $ stateId );
114
+ return redirect (route ('cities.index ' ) . "?state_id= " . $ stateId );
114
115
}
115
116
}
0 commit comments