Last active
August 29, 2015 13:56
-
-
Save morganhein/9254678 to your computer and use it in GitHub Desktop.
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
<?php | |
class Department extends Eloquent { | |
protected $guarded = array(); | |
public static $rules = array(); | |
/** | |
* The database table used by the model. | |
* | |
* @var string | |
*/ | |
protected $table = 'shifts'; | |
/** | |
* Get the unique identifier for the this model | |
* | |
* @return mixed | |
*/ | |
public function getIdentifier() | |
{ | |
return $this->getKey(); | |
} | |
public function job() | |
{ | |
return $this->belongsTo('Job'); | |
} | |
} |
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
<?php | |
class DepartmentsController extends BaseController { | |
/** | |
* Display a listing of the resource. | |
* | |
* @return Response | |
*/ | |
public function index($jobId) | |
{ | |
Clockwork::startEvent('List_Default_Departments', 'Starting.');\ | |
$positions = Auth::user()->jobs()->where('job_id', '=',$jobId)->departments(); | |
Clockwork::endEvent('List_Default_Departments', 'Done.'); | |
return Response::json($positions); | |
} | |
} | |
?> |
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
file: "/media/Misc/Projects/Purple Crown/server/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php" | |
line: 1891 | |
message: "Call to undefined method Illuminate\Database\Query\Builder::departments()" | |
type: "BadMethodCallException" |
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
<?php | |
class Job extends Eloquent { | |
protected $guarded = array(); | |
public static $rules = array(); | |
/** | |
* The database table used by the model. | |
* | |
* @var string | |
*/ | |
protected $table = 'jobs'; | |
/** | |
* Get the unique identifier for the this model | |
* | |
* @return mixed | |
*/ | |
public function getIdentifier() | |
{ | |
return $this->getKey(); | |
} | |
/** | |
* Relationships | |
*/ | |
public function user() | |
{ | |
return $this->belongsTo('User', 'user_id'); | |
} | |
public function departments() | |
{ | |
return $this->hasMany('Department'); | |
} | |
} |
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
<?php | |
Route::resource('/v1/jobs', 'JobController'); | |
Route::resource('/v1/jobs.departments', 'DepartmentController'); | |
?> | |
//so: www.example.com/v1/jobs/1/departments/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment