Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Peter demo #6

wants to merge 2 commits into from

Conversation

PeterSadlon
Copy link

Here you go @A5hleyRich

Copy link
Contributor

@A5hleyRich A5hleyRich left a 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.

Comment on lines +21 to +24
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');
Copy link
Contributor

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();
Copy link
Contributor

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.

Comment on lines +17 to +21
$table->id();
$table->string('title');
$table->decimal('amount');
$table->dateTime('transaction_date');
$table->timestamps();
Copy link
Contributor

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.

Comment on lines +42 to +51
$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();
Copy link
Contributor

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();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants