Change tab to space

Using PSR-2 standard.
This commit is contained in:
Hernawan Fa'iz Abdillah 2016-03-30 14:42:16 +07:00
parent b2510a01e4
commit 942b8fefb4
8 changed files with 64 additions and 64 deletions

View File

@ -2,8 +2,8 @@
class {{name}} extends Controller class {{name}} extends Controller
{ {
const MODEL = "{{model}}"; const MODEL = "{{model}}";
use RESTActions; use RESTActions;
} }

View File

@ -6,54 +6,54 @@ use Illuminate\Http\Response;
trait RESTActions { trait RESTActions {
public function all() public function all()
{ {
$m = self::MODEL; $m = self::MODEL;
return $this->respond(Response::HTTP_OK, $m::all()); return $this->respond(Response::HTTP_OK, $m::all());
} }
public function get($id) public function get($id)
{ {
$m = self::MODEL; $m = self::MODEL;
$model = $m::find($id); $model = $m::find($id);
if(is_null($model)){ if(is_null($model)){
return $this->respond(Response::HTTP_NOT_FOUND); return $this->respond(Response::HTTP_NOT_FOUND);
} }
return $this->respond(Response::HTTP_OK, $model); return $this->respond(Response::HTTP_OK, $model);
} }
public function add(Request $request) public function add(Request $request)
{ {
$m = self::MODEL; $m = self::MODEL;
$this->validate($request, $m::$rules); $this->validate($request, $m::$rules);
return $this->respond(Response::HTTP_CREATED, $m::create($request->all())); return $this->respond(Response::HTTP_CREATED, $m::create($request->all()));
} }
public function put(Request $request, $id) public function put(Request $request, $id)
{ {
$m = self::MODEL; $m = self::MODEL;
$this->validate($request, $m::$rules); $this->validate($request, $m::$rules);
$model = $m::find($id); $model = $m::find($id);
if(is_null($model)){ if(is_null($model)){
return $this->respond(Response::HTTP_NOT_FOUND); return $this->respond(Response::HTTP_NOT_FOUND);
} }
$model->update($request->all()); $model->update($request->all());
return $this->respond(Response::HTTP_OK, $model); return $this->respond(Response::HTTP_OK, $model);
} }
public function remove($id) public function remove($id)
{ {
$m = self::MODEL; $m = self::MODEL;
if(is_null($m::find($id))){ if(is_null($m::find($id))){
return $this->respond(Response::HTTP_NOT_FOUND); return $this->respond(Response::HTTP_NOT_FOUND);
} }
$m::destroy($id); $m::destroy($id);
return $this->respond(Response::HTTP_NO_CONTENT); return $this->respond(Response::HTTP_NO_CONTENT);
} }
protected function respond($status, $data = []) protected function respond($status, $data = [])
{ {
return response()->json($data, $status); return response()->json($data, $status);
} }
} }

View File

@ -1 +1 @@
'{{name}}' => $faker->{{type}}, '{{name}}' => $faker->{{type}},

View File

@ -4,13 +4,13 @@ use Illuminate\Database\Eloquent\Model;
class {{name}} extends Model class {{name}} extends Model
{ {
protected $fillable = [{{fillable}}]; protected $fillable = [{{fillable}}];
protected $dates = [{{dates}}]; protected $dates = [{{dates}}];
public static $rules = [ public static $rules = [
{{rules}} {{rules}}
]; ];
{{relations}} {{relations}}

View File

@ -1,4 +1,4 @@
public function {{name}}() public function {{name}}()
{ {
return $this->{{type}}("{{model}}")->withTimestamps(); return $this->{{type}}("{{model}}")->withTimestamps();
} }

View File

@ -1,4 +1,4 @@
public function {{name}}() public function {{name}}()
{ {
return $this->{{type}}("{{model}}"); return $this->{{type}}("{{model}}");
} }

View File

@ -1 +1 @@
"{{name}}" => "{{rule}}", "{{name}}" => "{{rule}}",

View File

@ -7,16 +7,16 @@ class {{name}} extends Seeder
{ {
public function run() public function run()
{ {
$faker = Faker::create(); $faker = Faker::create();
$firstIds = DB::table('{{first_table}}')->lists('id'); $firstIds = DB::table('{{first_table}}')->lists('id');
$secondIds = DB::table('{{second_table}}')->lists('id'); $secondIds = DB::table('{{second_table}}')->lists('id');
for($i = 0; $i < {{count}}; $i++) { for($i = 0; $i < {{count}}; $i++) {
DB::table('{{first_resource}}_{{second_resource}}')->insert([ DB::table('{{first_resource}}_{{second_resource}}')->insert([
'{{first_resource}}_id' => $faker->randomElement($firstIds), '{{first_resource}}_id' => $faker->randomElement($firstIds),
'{{second_resource}}_id' => $faker->randomElement($secondIds) '{{second_resource}}_id' => $faker->randomElement($secondIds)
]); ]);
} }
} }
} }