mirror of
https://github.com/ZorgCC/lumen-generators.git
synced 2024-12-26 14:05:29 +03:00
Change tab to space
Using PSR-2 standard.
This commit is contained in:
parent
b2510a01e4
commit
942b8fefb4
@ -2,8 +2,8 @@
|
||||
|
||||
class {{name}} extends Controller
|
||||
{
|
||||
const MODEL = "{{model}}";
|
||||
const MODEL = "{{model}}";
|
||||
|
||||
use RESTActions;
|
||||
use RESTActions;
|
||||
|
||||
}
|
||||
|
@ -6,54 +6,54 @@ use Illuminate\Http\Response;
|
||||
trait RESTActions {
|
||||
|
||||
|
||||
public function all()
|
||||
{
|
||||
$m = self::MODEL;
|
||||
return $this->respond(Response::HTTP_OK, $m::all());
|
||||
}
|
||||
public function all()
|
||||
{
|
||||
$m = self::MODEL;
|
||||
return $this->respond(Response::HTTP_OK, $m::all());
|
||||
}
|
||||
|
||||
public function get($id)
|
||||
{
|
||||
$m = self::MODEL;
|
||||
$model = $m::find($id);
|
||||
if(is_null($model)){
|
||||
return $this->respond(Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
return $this->respond(Response::HTTP_OK, $model);
|
||||
}
|
||||
public function get($id)
|
||||
{
|
||||
$m = self::MODEL;
|
||||
$model = $m::find($id);
|
||||
if(is_null($model)){
|
||||
return $this->respond(Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
return $this->respond(Response::HTTP_OK, $model);
|
||||
}
|
||||
|
||||
public function add(Request $request)
|
||||
{
|
||||
$m = self::MODEL;
|
||||
$this->validate($request, $m::$rules);
|
||||
return $this->respond(Response::HTTP_CREATED, $m::create($request->all()));
|
||||
}
|
||||
public function add(Request $request)
|
||||
{
|
||||
$m = self::MODEL;
|
||||
$this->validate($request, $m::$rules);
|
||||
return $this->respond(Response::HTTP_CREATED, $m::create($request->all()));
|
||||
}
|
||||
|
||||
public function put(Request $request, $id)
|
||||
{
|
||||
$m = self::MODEL;
|
||||
$this->validate($request, $m::$rules);
|
||||
$model = $m::find($id);
|
||||
if(is_null($model)){
|
||||
return $this->respond(Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
$model->update($request->all());
|
||||
return $this->respond(Response::HTTP_OK, $model);
|
||||
}
|
||||
public function put(Request $request, $id)
|
||||
{
|
||||
$m = self::MODEL;
|
||||
$this->validate($request, $m::$rules);
|
||||
$model = $m::find($id);
|
||||
if(is_null($model)){
|
||||
return $this->respond(Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
$model->update($request->all());
|
||||
return $this->respond(Response::HTTP_OK, $model);
|
||||
}
|
||||
|
||||
public function remove($id)
|
||||
{
|
||||
$m = self::MODEL;
|
||||
if(is_null($m::find($id))){
|
||||
return $this->respond(Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
$m::destroy($id);
|
||||
return $this->respond(Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
public function remove($id)
|
||||
{
|
||||
$m = self::MODEL;
|
||||
if(is_null($m::find($id))){
|
||||
return $this->respond(Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
$m::destroy($id);
|
||||
return $this->respond(Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
protected function respond($status, $data = [])
|
||||
{
|
||||
return response()->json($data, $status);
|
||||
return response()->json($data, $status);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
'{{name}}' => $faker->{{type}},
|
||||
'{{name}}' => $faker->{{type}},
|
@ -4,13 +4,13 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class {{name}} extends Model
|
||||
{
|
||||
protected $fillable = [{{fillable}}];
|
||||
protected $fillable = [{{fillable}}];
|
||||
|
||||
protected $dates = [{{dates}}];
|
||||
protected $dates = [{{dates}}];
|
||||
|
||||
public static $rules = [
|
||||
public static $rules = [
|
||||
{{rules}}
|
||||
];
|
||||
];
|
||||
|
||||
{{relations}}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
public function {{name}}()
|
||||
{
|
||||
return $this->{{type}}("{{model}}")->withTimestamps();
|
||||
}
|
||||
public function {{name}}()
|
||||
{
|
||||
return $this->{{type}}("{{model}}")->withTimestamps();
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
public function {{name}}()
|
||||
{
|
||||
return $this->{{type}}("{{model}}");
|
||||
}
|
||||
public function {{name}}()
|
||||
{
|
||||
return $this->{{type}}("{{model}}");
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
"{{name}}" => "{{rule}}",
|
||||
"{{name}}" => "{{rule}}",
|
@ -7,16 +7,16 @@ class {{name}} extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$faker = Faker::create();
|
||||
$faker = Faker::create();
|
||||
|
||||
$firstIds = DB::table('{{first_table}}')->lists('id');
|
||||
$secondIds = DB::table('{{second_table}}')->lists('id');
|
||||
$firstIds = DB::table('{{first_table}}')->lists('id');
|
||||
$secondIds = DB::table('{{second_table}}')->lists('id');
|
||||
|
||||
for($i = 0; $i < {{count}}; $i++) {
|
||||
DB::table('{{first_resource}}_{{second_resource}}')->insert([
|
||||
'{{first_resource}}_id' => $faker->randomElement($firstIds),
|
||||
'{{second_resource}}_id' => $faker->randomElement($secondIds)
|
||||
]);
|
||||
DB::table('{{first_resource}}_{{second_resource}}')->insert([
|
||||
'{{first_resource}}_id' => $faker->randomElement($firstIds),
|
||||
'{{second_resource}}_id' => $faker->randomElement($secondIds)
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user