I have an app, where a user can pick a property they own and log an expense for it. Each expense has its own id and is associated with the property id.
I'm trying to create a show page, where I can display all the expenses logged with that property.
The expense table is this
The controller is like this
public function index(){
$properties = PropertyAdvert::where('user_id', Auth::user()->id)->get();
return view('/pages/expenses/index', compact('properties', 'data'));
}
public function create($id){
$property = PropertyAdvert::where('id', $id)->first();
return view('/pages/expenses/create', compact('property'));
}
public function store(Request $request){
$PropertyExpenses = PropertyExpense::create([
"property_id" => $request->property_id,
"user_id" => Auth::user()->id,
"expenseDescription" => $request->description,
"cost" => $request->amount,
"date" => $request->date,
"category" => $request->category
]);
return "Expense Log";
}
public function show($id){
$PropertyExpenses = PropertyExpense::where('property_id', $id)->get();
}
The route is this
Route::get('/expenses/{propertyid}/{expenseid}', 'PropertyExpenseController@show')->middleware('auth');
I don't think I'm going about this the right way.
I want to display all expenses of one property on one page. Each expense also has its own unique id. But a property_id in common
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire