I am trying to get all rows in a payments table where I have another table called projects I want to get all rows that in payments table where project_id column = ID of the row inside projects table I am using Laravel framework please help me this some the code
Payment Model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Payment extends Model
{
protected $table = 'payments';
public function projects() {
return $this->belongsTo('App\Project');
}
}
Project Model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
protected $table = "projects";
public function payments() {
return $this->hasMany('App\Payment');
}
}
Route File
Route::get('special/{project_id}', 'SpecialController@index');
The index function in the Controller
<?php
namespace App\Http\Controllers;
use App\Project;
use App\Payment;
use Illuminate\Http\Request;
class SpecialController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Project $project_id)
{
return view('special.index')->with(['projects' => $project_id]);
}
This is my problem please help
All the best