JokersMild85

Experience

3,090

0 Best Reply Awards

  • Member Since 11 Months Ago
  • 22 Lessons Completed
  • 0 Favorites

12th January, 2018

JokersMild85 started a new conversation PHPunit Tutorial • 9 months ago

Can anyone recommend a good tutorial on how to use PHPunit for beginners? I'm watching the "Lets Build a Forum" tutorial on Laracasts and he is using PHPunit but not really explaining how he gets it to work.

4th January, 2018

JokersMild85 started a new conversation How To Delete Record • 9 months ago

What is the proper way to delete a record in Laravel? Does it have to go through the destroy method?

        if(!empty($request['delete']))
        {    
            foreach($request['delete'] as $delete)
            {
                $workout_exercise = WorkoutExercise::findOrFail($delete['id']);
                
                $workout_exercise->delete();
            }
        }

20th December, 2017

JokersMild85 left a reply on Formatting Form For Update • 10 months ago

Maybe this is a bit closer...

<form method="POST" action="{{ route('workouts.update', ['id'=>$workout['workout_id']]) }}">

The error I am receiving is: Missing required parameters for [Route: {$route->getName()}] [URI: {$route->uri()}].

JokersMild85 started a new conversation Formatting Form For Update • 10 months ago

Need a little help on how to set up my form action for my update form. Here's what I have:

<form method="POST" action="{{ action('workouts.update', $id = $workout['workout_id']) }}">
    {{ csrf_field() }}
    {{ method_field('PATCH') }}

I have no idea if I'm close or way off here. Any help would be appreciated.

18th December, 2017

JokersMild85 left a reply on HasMany Relationship Not Working • 10 months ago

It works in QueryBuilder but if I use it in a statement like I'm trying to now, that's the error in receiving.

JokersMild85 left a reply on HasMany Relationship Not Working • 10 months ago

select isn't a usable method in Eloquent

JokersMild85 left a reply on HasMany Relationship Not Working • 10 months ago

$workout->workout_exercises->all();

This worked but is there a way I can return specific columns instead of all of them?

JokersMild85 left a reply on HasMany Relationship Not Working • 10 months ago

So how would I retrieve all of the workout_exercises of $workout? The example provided in the documentation still give me the same error?

JokersMild85 started a new conversation HasMany Relationship Not Working • 10 months ago

A workout has many workout_exercises:

Workout Model:

class Workout extends Model
{
    //
    protected $fillable = [
        'user_id',
        'name',
        'published_at'
    ];
    
    public function workout_exercises()
    {
        return $this->hasMany('App\WorkoutExercise');
    }
    
    public function user()
    {
        return $this->belongsTo('App\User');
    }
}

A workout_exercise belongs to a workout

Workout_Exercise Model

class WorkoutExercise extends Model
{
    //
    protected $fillable = [
        'workout_id',
        'exercise_id',
        'we_set_num',
        'we_rep_num',
        'we_set_complete',
    ];
    
    public function workout(){
        return $this->belongsTo('App\Workout');
    }

    public function exercise(){
        return $this->belongsTo('App\Exercise');
    }
}

When I define my $workout object and then run the following statement, I receive a 'trying to get property on non-object' error

$workout->workout_exercises->get();

Any suggestions?

8th December, 2017

JokersMild85 left a reply on Method Not Allowed Error • 10 months ago

Okay, I fixed the problem.

Instead of my form action using 'route': '''

'''

I changed it to 'action': '''

'''

Can anyone provide any insight into why this would work instead of using 'route' ?

JokersMild85 left a reply on Method Not Allowed Error • 10 months ago

Changed the order of my routes so that my custom ones are listed before my resource and I changed the the workouts.step to workouts/step.

Receiving an undefined route error now.

7th December, 2017

JokersMild85 started a new conversation Method Not Allowed Error • 10 months ago

I know I am receiving this error because Laravel thinks the route is not defined but it is. Any assistance would be appreciated. (The route in question is Route::post('workouts.step, '[email protected]')

Here is the route:

Route::resource('workouts', 'WorkoutsController'); Route::post('workouts.step', '[email protected]'); Route::get('workouts/{workout}/addToWorkout', '[email protected]');

Controller:

public function step(CreateWorkoutRequest $request)
{
    $values = $request->input('exercise');
    $workout_name = $request->input('workout_name');

    for($i=0;$i<count($values);$i++)
    {
        $array = explode(",", $values[$i]);

        $exercises[$i]['exercise_id'] = $array[0];
        $exercises[$i]['exercise_type_id'] = $array[1];
        $exercises[$i]['exercise_name'] = $array[2];
    }

    return view('workouts.step', compact('exercises','workout_name'));
}

View:

@extends('layouts.app')

@section('content')

Create New Workout

@if ($errors->any())

@endif

{{ csrf_field() }}
<div class="form-group">
    <h2>Name Workout: </h2>
    <input type="text" name="workout_name">
</div>

@foreach($exercise_types as $exercise_type)

<div class="form-group">
    <h2>{{$exercise_type->exercise_type}}</h2>
    </br>

    @foreach($exercise_type->exercises as $exercise)
        <label for="{{ $exercise->exercise_name }}">{{ $exercise->exercise_name }}</label>
        <input type="checkbox" name="exercise[]" value="{{ $exercise->id }},{{ $exercise->exercise_type_id }},{{ $exercise->exercise_name }}" id="{{ $exercise->exercise_name }}"></br>
    @endforeach

</div>

</br>

@endforeach

@endsection

28th November, 2017

JokersMild85 left a reply on Assign Attributes To Form Elements • 10 months ago

Ok, thank you. Only used it because that is what was being used in the Laracasts tutorial.

JokersMild85 left a reply on Assign Attributes To Form Elements • 10 months ago

I'm sorry, I'm still getting used to working in Laravel. Where would this function be placed so I can call it?

JokersMild85 left a reply on Assign Attributes To Form Elements • 10 months ago

Don't need to use double brackets if they are already inside the {!! !!} brackets. I had to use double quotes instead of the single quotes in the value parameter to fix that.

@foreach($exercise_type->exercises as $exercise)

    {!! Form::label('exercise_name', $exercise->exercise_name) !!}
    {!! Form::checkbox( 'exercise[]', "{$exercise->id},{$exercise->exercise_type_id},{$exercise->exercise_name}") !!}
    </br>

@endforeach 

Why is it that I can't find an answer for adding an attribute to form elements? This shouldn't be that hard to do.

JokersMild85 started a new conversation Assign Attributes To Form Elements • 10 months ago

I asked this question a couple of days ago but the answers I received did not resolve my problem. I am trying to assign attributes to form elements, namely an ID attribute to my form checkboxes. When I attempt to do this, all it does is set all the checkboxes in my form to checked. Any thoughts why this is happening and how to successfully assign my checkboxes an ID attribute?

@foreach($exercise_type->exercises as $exercise)

    {!! Form::label('exercise_name', $exercise->exercise_name) !!}
    {!! Form::checkbox( 'exercise[]', '{$exercise->id}_{$exercise->exercise_type_id}_{$exercise->exercise_name}', ['id' => '{$exercise->exercise_name}'] ) !!}
    </br>

@endforeach

26th November, 2017

JokersMild85 left a reply on Assign Id Attribute To Form Checkbox Element • 10 months ago

Can you please clarify how the example you provided sets the id property of the checkbox element?

JokersMild85 started a new conversation Assign Id Attribute To Form Checkbox Element • 10 months ago

I'm trying to assign an id attribute to checkbox elements of my form. What I am writing is causing the checkboxes to be checked by default and not providing an id attribute. Can anyone provide some insight?

Here is the code:

@foreach($exercise_types as $exercise_type)

{!! Form::label('exercise_type', $exercise_type->exercise_type) !!}
@foreach($exercise_type->exercises as $exercise)

    {!! Form::label('exercise_name', $exercise->exercise_name) !!}
    {!! Form::checkbox( 'exercise[]', "{$exercise->id},{$exercise->exercise_type_id},{$exercise->exercise_name}"), ['id' => "{$exercise->exercise_name}"] !!}
    </br>

@endforeach

@endforeach

14th November, 2017

JokersMild85 left a reply on Undefined Offset Error • 11 months ago

Yep, ran dd($values) after I selected 3 checkboxes and it returned 3 values for each array: sets, reps, and e_id. Not sure why it is looking for a 4th array key.

JokersMild85 left a reply on Undefined Offset Error • 11 months ago

They all exist. I'm inspecting the elements of the page and they are all returning values.

JokersMild85 started a new conversation Undefined Offset Error • 11 months ago

No idea why I am getting this error, can anyone provide some guidance?

public function store(Request $request)
{
    $values = $request->all();
    $id = Auth::id();
    
    echo "<h2>User ID: ".$id."</h2>";
    
    for($i=0;$i<count($values);$i++)
    {
        $e_id = $values['e_id'][$i];
        echo "<h4>Exercise ID: ".$e_id."</h4>";
        $sets = $values['sets'][$i];
        echo "<h4>Sets: ".$sets."</h4>";
        $reps = $values['reps'][$i];
        echo "<h4>Reps: ".$reps."</h4>";
    } 

}

11th November, 2017

JokersMild85 started a new conversation Problem Retrieving Values From Imported Array • 11 months ago

I'm receiving an error when I try to output some values from an array. The error I'm receiving is "Trying to get property of non-object". Can someone take a look at my code and see what I'm doing wrong?

Controller method:

public function step(Request $request)
{
    $values = $request->input('exercise');
    
    for($i=0;$i<count($values);$i++){
        $array = explode("-", $values[$i]);
        
        $exercises[$i]['exercise_id'] = $array[0];
        $exercises[$i]['exercise_type_id'] = $array[1];
        $exercises[$i]['exercise_name'] = $array[2];
    }

    return view('workouts.step', compact('exercises'));
}

Code from the view:

@foreach($exercises as $exercise)

{{ $exercise->exercise_name }}

@endforeach

Right now I'm just trying to get output from one of the array keys , exercise_name.

10th November, 2017

JokersMild85 started a new conversation Save Multiple Checkbox Values To $request Array And Retrieve Them • 11 months ago

I'm trying to save multiple checkbox values from my form to the $request array but it is only saving one checkbox value.

Here is my code:

Here is the form:

@foreach($exercise_type->exercises as $exercise)

    {!! Form::label('exercise_name', $exercise->exercise_name) !!}
    {!! Form::checkbox( 'exercise[]', "{$exercise->id}-{$exercise->exercise_type_id}-{$exercise->exercise_name}") !!}
    </br>

@endforeach 

Here is the code for retrieving the Request array values:

public function store(Request $request)
{
    $values = $request->input('exercise');
    
    return $values;
}

8th November, 2017

JokersMild85 left a reply on Foreach Loop In HTML Form Builder Form • 11 months ago

Gotcha, didn't realize that's what you were doing. I appreciate the help, thank you.

JokersMild85 left a reply on Foreach Loop In HTML Form Builder Form • 11 months ago

That did it, thanks. Is it possible to string those multiple variables together in the second parameter?

JokersMild85 started a new conversation Foreach Loop In HTML Form Builder Form • 11 months ago

I wish I could more eloquently explain what I am trying to accomplish here but I am still quite new to Laravel so please forgive if I misuse any terminology in my explanation.

I am trying to apply a foreach loop to my form that I built using the Laravel Collective HTML Form Builder (...correct?) and apply the values I pull from the database to the value fields of the form.

The output it is giving me is what is literally typed in my code. I know its because of the single quotation marks but if I remove them I get a syntax error for not including them.

Here is my code below as it will probably explain what I am trying to do better than how I am describing it.

The controller create function:

public function create()
{
    //
    $exercise_types = ExerciseType::all();
    
    return view('workouts.create', ['exercise_types' => $exercise_types]);
}

The create view:

@extends('layouts.app')

@section('content')

Create New Workout

{!! Form::open(['url' => 'workouts']) !!}

@include ('workouts.form', ['submitButtonText' => 'Create Workout'])

{!! Form::close() !!}

@endsection

The form view itself:

@foreach($exercise_types as $exercise_type)

{!! Form::label('exercise_type', '{{ $exercise_type->exercise_type }}:') !!}
@foreach($exercise_type->exercises as $exercise)

    {!! Form::checkbox( '{{ $exercise->exercise_name }}', '{{ $exercise->id }}-{{ $exercise->exercise_type_id }}-{{ $exercise->exercise_name }}') !!}

@endforeach

@endforeach

{!! Form::submit($submitButtonText, ['class' => 'btn btn-primary form-control']) !!}

Any guidance would be appreciated.

7th November, 2017

JokersMild85 left a reply on Set Logout Route In Laravel 5.5 • 11 months ago

Neither of these solutions resolve the problem. I receive the timeout page if I logout of my session immediately after logging in.

I did not delete the {{ csrf_field() }} from the logout form.

The only thing I did that I think began this problem was changing the redirect on login from the default Home page to a different page.

6th November, 2017

JokersMild85 started a new conversation Set Logout Route In Laravel 5.5 • 11 months ago

Not sure what I did but when I logout of my session it redirects to a weird timeout due inactivity page on my site. Does anyone know where I can set my route on logout?

JokersMild85 left a reply on Archived Video Series • 11 months ago

Working for me now in the original browser 1 hour after trying the first time... Thanks for the help.

JokersMild85 started a new conversation Archived Video Series • 11 months ago

If a video series has been archived, is it no longer viewable? I was working with the Laravel 5 fundamentals series and none of the videos will play now. Videos of other series play fine.

1st November, 2017

JokersMild85 left a reply on Laravel 5.5 Doesn't Recognize A Variable • 11 months ago

Originally the controller code looked like this when I was receiving the undefined variable error:

class ArticlesController extends Controller {

public function show($id)
{     
    $article = Article::findOrFail($id);
    
    return view('articles.show', compact('article'));
}

public function edit($id)
{
    $article = Article::findOrFail($id);
    
    return view('articles.edit');
}

}

Once I added the compact('article) code to the Edit function the same way I applied it to the Show function, it worked fine.

Obvious mistake once you figure out what is causing the problem.

Thanks again guys.

JokersMild85 left a reply on Laravel 5.5 Doesn't Recognize A Variable • 11 months ago

Never mind, I figured it out as I was posting my code. Thanks anyway. I'm sure I'll be posting more questions here in the near future.

JokersMild85 started a new conversation Laravel 5.5 Doesn't Recognize A Variable • 11 months ago

So I'm working through the Laravel 5 Fundamentals series on episode 13 where I just created the Articles resource controller and added the Edit view... not exactly complicated stuff. However, I am receiving an error message saying that I have an undefined variable $article.

I most definitely defined the variable correctly and the code for the Edit function is basically identical to the Show function. There are no syntax errors, the function returns the articles.edit view fine but it just does not want to recognize the $article variable. Any suggestions what I am doing wrong?

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.