Skip to content

Instantly share code, notes, and snippets.

@morganhein
Last active August 29, 2015 13:56
Show Gist options
  • Save morganhein/9254678 to your computer and use it in GitHub Desktop.
Save morganhein/9254678 to your computer and use it in GitHub Desktop.
<?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');
}
}
<?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);
}
}
?>
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"
<?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');
}
}
<?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