Ev-genius

Ev-genius

Member Since 1 Month Ago

Experience Points
2,100
Total
Experience

2,900 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
17
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
2,100 XP
Oct
04
3 weeks ago
Activity icon

Replied to Why PHP Variable Not Recognize In Blade @if Condition?

@snapey

That better. Thanks for the advice!

Activity icon

Replied to Why PHP Variable Not Recognize In Blade @if Condition?

@michaloravec exactly! Thanks a lot! spent an hour looking for an error...

Activity icon

Started a new Conversation Why PHP Variable Not Recognize In Blade @if Condition?

Hello!

Try to filter by day...

@php
$dn = date('N', strtotime($days)); // 1
@endphp

@foreach ($program->exercises as $exercise )
	@if ( $exercise->pivot->day_of_week === $dn )
	{{ $exercise->name }}<br>
	@endif
@endforeach

outputs nothing

but if i replace the variable with a digit

@php
$dn = date('N', strtotime($days)); // 1
@endphp

@foreach ($program->exercises as $exercise )
	@if ( $exercise->pivot->day_of_week === 1 )
	{{ $exercise->name }}<br>
	@endif
@endforeach

exercises are shown...

Whats wrong with $dn variable?

Sep
29
1 month ago
Activity icon

Replied to How To Get Just The Data I Need For A Template?

@automica thank you for the explanation! Relationship setup is clear!

But I cannot figure out how I can configure the controller to get data for this view.

to put it simply, I need something like this

<h1>
SELECT * from Programs where id=1 // program "for mass" in table, mysite.com/programs/1
</h1>

<h2>Odd week</h2> // defined hard in template while

for ($i = 1; $i <= 7; $i++) // from monday to sunday
<ul>

   <li><h3>Day of week: {{ $i }}</h3> // header for Monday/Thuesday/.../Sunday
      <ul>
         <li>
            SELECT the exercises that are contained in program id=1, on an odd week, on $i day
	    // list of exercises for $i day (Monday/Thuesday/.../Sunday) for odd week
         </li>                  
      </ul>

   </li>
</ul>

How much of the logic should be in the model and how much in the view?

Sep
28
1 month ago
Activity icon

Replied to How To Get Just The Data I Need For A Template?

@automica what to do to expect table name "exercise_program_timetable"? I have three models, between which all have a many-to-many relationship How to set relations between three or more tables? Tried change models method names to camelCase... not working

yes, wrong code part, it's from example... can't edit post

correct code

<h4>{{ $program->name }}</h4>

<h5>Odd week</h5>

@for ($i = 1; $i <= 7; $i++)
<ul>
   <li><h6>Day of week: {{ $i }}</h6>
      <ul>
         @foreach ($program->timetables as $timetable)
            @if ( $timetable->week === 'odd' && $timetable->day_of_week === $i )
               @foreach ($menu->exercises as $exercise)
                  @if ($loop->first)
                  <li>{{ $exercise->name }}</li>
                  @endif
               @endforeach
            @endif
         @endforeach
      </ul>
   </li>
</ul>
@endfor

the timetable is compiled for an even and an odd week, and then shown to the user depending on which week is now - even or odd

now odd or even week defined hard in template

week === 'odd'

in future of course it will need to be determined depending on the date on which we show the schedule it doesn't matter yet

how to remove all logic from the template? or is it okay to do this?

Activity icon

Started a new Conversation How To Get Just The Data I Need For A Template?

Hello!

I have three table and one linking table

programs table

id | name
1  | for mass
2  | for strength
exercises table

id | name
1  | arms-exercise-1
2  | arms-exercise-2
3  | arms-exercise-3
4  | arms-exercise-4
5  | legs-exercise-1
6  | legs-exercise-2
7  | legs-exercise-3
8  | legs-exercise-4
timetables

id | week | day_of_week 
1  | odd  | 1
2  | odd  | 2
3  | odd  | 3
4  | odd  | 4
5  | odd  | 5
6  | odd  | 6
7  | odd  | 7
8  | even | 1
9  | even | 2
10 | even | 3
11 | even | 4
12 | even | 5
13 | even | 6
14 | even | 7
exercise_program_timetable linking table

id | program_id | exercise_id | timetable_id
1  |         1→ | 1→          | 1→
2  |         1→ | 2→          | 2→
3  |         1→ | 1→          | 3→
4  |         1→ | 3→          | 4→
6  |         1→ | 1→          | 5→
7  |         1→ | 4→          | 6→
8  |         1→ | 5→          | 7→

And relationships in models

class Program extends Model
{

    public function Exercises()
    {
        return $this->belongsToMany(Exercise::class, 'exercise_program_timetable');
    }

    public function Timetables()
    {
        return $this->belongsToMany(Timetable::class, 'exercise_program_timetable');
    }
}
class Exercise extends Model
{    

    public function Programs()
    {
        return $this->belongsToMany(Program::class, 'exercise_program_timetable');
    }

    public function Timetables()
    {
        return $this->belongsToMany(Timetable::class, 'exercise_program_timetable');
    }

}
class Timetable extends Model
{

    public function Programs()
    {
        return $this->belongsToMany(Program::class, 'exercise_program_timetable');
    }

    public function Exercises()
    {
        return $this->belongsToMany(Exercise::class, 'exercise_program_timetable');
    }

}

My questions:

Firstly, without specifying the linking table

... ::class, 'exercise_program_timetable');

Laravel says I can't find the table... Is this how it should be?

I need to show a schedule of program "for mass" , for example from today and 10 days in advance, based on table "timetables"

in controller

public function show(Program $program)
{
	$program->load('exercise.timetabless')->get();
        return response()->view('programs.show', ['program' => $program]);
}

and trash in view ))

<h4>{{ $program->name }}</h4>

<h5>Odd week</h5>

@for ($i = 1; $i <= 7; $i++)
<ul>
	<li><h6>Day of week: {{ $i }}</h6>
		<ul>
			@foreach ($program->menus as $menu)
				@if ( $menu->week === 'odd' && $menu->day_of_week === $i )
					@foreach ($menu->dishes as $dish)
						<li>{{ $dish->name }}</li>
					@endforeach
				@endif
			@endforeach
		</ul>
	</li>
</ul>
@endfor

Firstly, exercises for the day are shown several times (according to the number of entries in the linking table) Well, and secondly, is it basically wrong?

How can I get only the data I need so that the logic is in the model and so that such a list can be built

Name of program
	Odd week
		Day_of_week(1)
			Exercise_1
			...
			Exercise_N

		Day_of_week(2)
			Exercise_1
			...
			Exercise_N
...
...
...
		Day_of_week(7)
			Exercise_1
			...
			Exercise_N
Sep
27
1 month ago
Activity icon

Replied to How To Use Blade Inside Js

You are right ... did not think about it.

Activity icon

Started a new Conversation How To Use Blade Inside Js

Hello!

Need to add modal dinamically

...
modhtml += '<div class="modal-body">';
modhtml += '<div class="row  mt-3">';
modhtml += '@foreach ($categories as $category)';
modhtml += '<h4>{{ $category->name }}</h4>';
modhtml += '@endforeach';
modhtml += '</div>';
modhtml += '</div>';
...

and then

$('#mod-1').append(modhtml);

but in source html it look like this

<div class="modal-body">
<div class="row  mt-3">
"@foreach ($categories as $category)"
"@endforeach"
</div>
</div>

All Blade code like text... Where is my mistake?

Sep
24
1 month ago
Activity icon

Replied to Linking Table

Thank you again!

Activity icon

Replied to Linking Table

Oh, it works! Thank you very much!

Сan i ask one more question? Maybe it would be more correct to make a table "training diary"

diary

id | date       | part_of_day
1  | 2020.09.25 | morning
2  | 2020.09.25 | morning
3  | 2020.09.25 | noon
4  | 2020.09.25 | noon
5  | 2020.09.25 | morning
6  | 2020.09.25 | noon
7  | 2020.09.25 | evening
8  | 2020.09.25 | evening

and linking table would be like this

diary_exercise_program linking table

id | diary_id | program_id | exercise_id
1  |       1→ | 1→         | 1→
2  |       1→ | 2→         | 1→
3  |       1→ | 5→         | 1→
4  |       1→ | 1→         | 1→
5  |       2→ | 1→         | 1→
6  |       2→ | 3→         | 1→
7  |       2→ | 7→         | 1→
8  |       2→ | 8→         | 1→

And one more model Diary. And many-to-many relationship between Exercise, Program and Diary.

Would it be more correct?

Activity icon

Started a new Conversation Linking Table

Hello!

Need to design a database for the training service. I made tables: Categories, exercises, programs and one linking table programs_exercises:

categories table

id | name
1  | for arms
2  | for legs
exercises table

id | category_id | name
1  |          1→ | arms-exercise-1
2  |          1→ | arms-exercise-2
3  |          1→ | arms-exercise-3
4  |          1→ | arms-exercise-4
5  |          2→ | legs-exercise-1
6  |          2→ | legs-exercise-2
7  |          2→ | legs-exercise-3
8  |          2→ | legs-exercise-4
programs table

id |	name
1  |	for mass
2  |	for strength
programs_exercises linking table

id | program_id | exercise_id
1  |         1→ | 1→ 
2  |         1→ | 2→ 
3  |         1→ | 5→ 
4  |         1→ | 1→ 
5  |         2→ | 1→ 
6  |         2→ | 3→ 
7  |         2→ | 7→ 
8  |         2→ | 8→ 

Now I need to make training programs for many days and part of day (morning, noon, evening). https://yadi.sk/i/HNgUbMVGk1ovPA

Can I add a date and part of day (morning, noon, evening) to the linking table? And then how to filter data by date when displaying programs? And how to insert data if the Date column is not the key to something?

programs_exercises linking table

id | program_id | exercise_id | date       | part_of_day
1  |         1→ | 1→          | 2020.09.25 | morning
2  |         1→ | 2→          | 2020.09.25 | morning
3  |         1→ | 5→          | 2020.09.25 | noon
4  |         1→ | 1→          | 2020.09.25 | noon
5  |         2→ | 1→          | 2020.09.25 | morning
6  |         2→ | 3→          | 2020.09.25 | noon
7  |         2→ | 7→          | 2020.09.25 | evening
8  |         2→ | 8→          | 2020.09.25 | evening

I mean that with such a request

$programs = Program::with('exercises')->get();

we will not get the date and morning/noon/evening from the link table.

Sep
09
1 month ago
Activity icon

Replied to How To Receive POST From Other Site

It worked! OMG It worked! Thank you Sinnbeck very very much!

I already tried to change get to a post, but when I went to this address myself, it showed an error, and I didn't even think to check. Of course ... the page was waiting for the Post...

well... went to repeat the basics.

Thank you again, Sinnbeck!

Activity icon

Replied to How To Receive POST From Other Site

set in VerifyCsrfToken.php

protected $except = [ 'callback' ];

Support on other site says it gets a 405 response

Activity icon

Replied to How To Receive POST From Other Site

Done.

in VerifyCsrfToken.php

protected $except = [ 'https://mysite.com/callback' ];

But nothing...

But if I go to the page myself, then an empty array is written in the logs. [2020-09-09 04:45:23] local.INFO: array ()

Am I sending the 200 response correctly? without this response, the other site does not transmit data

Activity icon

Started a new Conversation How To Receive POST From Other Site

POST request comes from another site to the page /callback Need to receive it, save data and send status 200 back.

View is not needed Tried to do it in routes, for sample:

use Illuminate\Http\Request;

Route::get('/callback', function (Request $request) {

$request = request()->post();

Log::info($request);
return response('', 200); });

if we specify the $request = '123', then the log is written

[2020-09-09 04:25:12] local.INFO: 123

otherwise the log is empty

What am I doing wrong?