-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tentando carregar as config do teste
- Loading branch information
Showing
31 changed files
with
5,882 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php namespace App; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Group extends Model { | ||
|
||
protected $fillable = ["name"]; | ||
|
||
protected $dates = []; | ||
|
||
public static $rules = [ | ||
"name" => "required", | ||
]; | ||
|
||
public function players() | ||
{ | ||
return $this->hasMany("App\Player"); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php namespace App\Http\Controllers; | ||
|
||
class GroupsController extends Controller { | ||
|
||
const MODEL = "App\Group"; | ||
|
||
use RESTActions; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php namespace App\Http\Controllers; | ||
|
||
class PlayersController extends Controller { | ||
|
||
const MODEL = "App\Player"; | ||
|
||
use RESTActions; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Response; | ||
|
||
trait RESTActions { | ||
|
||
|
||
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 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 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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php namespace App; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Player extends Model { | ||
|
||
protected $fillable = ["name", "group_id", "group_id"]; | ||
|
||
protected $dates = ["baithday"]; | ||
|
||
public static $rules = [ | ||
"name" => "required", | ||
"group_id" => "numeric", | ||
"group_id" => "required|numeric", | ||
]; | ||
|
||
public function group() | ||
{ | ||
return $this->belongsTo("App\Group"); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
return [ | ||
'default' => 'local', | ||
'migrations' => 'migrations', | ||
'connections' => [ | ||
'local' => [ | ||
'driver' => 'mysql', | ||
'host' => 'localhost', | ||
'database' => 'core', | ||
'username' => 'root', | ||
'password' => 'entrar', | ||
'charset' => 'utf8', | ||
'collation' => 'utf8_unicode_ci', | ||
'prefix' => '', | ||
'strict' => false, | ||
], | ||
'testing' => [ | ||
'driver' => 'mysql', | ||
'host' => 'localhost', | ||
'database' => 'core_test', | ||
'username' => 'root', | ||
'password' => 'entrar', | ||
'charset' => 'utf8', | ||
'collation' => 'utf8_unicode_ci', | ||
'prefix' => '', | ||
'strict' => false, | ||
], | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
return [ | ||
|
||
'default' => 'local', | ||
'migrations' => 'migrations', | ||
'connections' => [ | ||
'local' => [ | ||
'driver' => 'mysql', | ||
'host' => 'localhost', | ||
'database' => 'core_test', | ||
'username' => 'root', | ||
'password' => 'entrar', | ||
'charset' => 'utf8', | ||
'collation' => 'utf8_unicode_ci', | ||
'prefix' => '', | ||
'strict' => false, | ||
], | ||
'testing' => [ | ||
'driver' => 'mysql', | ||
'host' => 'localhost', | ||
'database' => 'core_test', | ||
'username' => 'root', | ||
'password' => 'entrar', | ||
'charset' => 'utf8', | ||
'collation' => 'utf8_unicode_ci', | ||
'prefix' => '', | ||
'strict' => false, | ||
], | ||
], | ||
]; |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.