-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Peter demo #6
base: master
Are you sure you want to change the base?
Peter demo #6
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Petrarca1304. I've reviewed this like I would any other member of the team so that you get a feel for our code reviews. A couple of comments for you.
Route::get('/dashboard', [TransactionsController::class, 'index'])->middleware(['auth'])->name('dashboard'); | ||
Route::post('/dashboard', [TransactionsController::class, 'store'])->middleware(['auth'])->name('dashboard'); | ||
Route::put('/dashboard', [TransactionsController::class, 'update'])->middleware(['auth'])->name('dashboard'); | ||
Route::delete('/dashboard', [TransactionsController::class, 'destroy'])->middleware(['auth'])->name('dashboard'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use a Resource Controller here:
https://laravel.com/docs/7.x/controllers#resource-controllers
public function destroy($id) | ||
{ | ||
$post = Transaction::find($id); | ||
$post->delete(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should validate that the current user owns the transaction.
$table->id(); | ||
$table->string('title'); | ||
$table->decimal('amount'); | ||
$table->dateTime('transaction_date'); | ||
$table->timestamps(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Transactions should be owned by a user.
$this->validate($request, [ | ||
'title'=>'required', | ||
'amount'=>'required', | ||
'transaction_date'=>'required' | ||
]); | ||
$transaction = new Transaction; | ||
$transaction->title=$request->input('title'); | ||
$transaction->amount=$request->input('amount'); | ||
$transaction->transaction_date=$request->input('transaction_date'); | ||
$transaction->save(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be simplified if using mass assignment:
https://laravel.com/docs/7.x/eloquent#mass-assignment
$validatedData = $request->validate([
'title'=>'required',
'amount'=>'required',
'transaction_date'=>'required'
]);
$transaction = new Transaction($validatedData);
$transaction->save();
Here you go @A5hleyRich