bortz

bortz

Member Since 1 Month Ago

Experience Points
830
Total
Experience

4,170 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
0
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
830 XP
Oct
23
1 day ago
Activity icon

Awarded Best Reply on How To Specify Attributes In Laravel Collective's Form::open?

Sorry. None of the above works. This works:

{!! Form::open([
    'action' =>  [
        'App\Http\Controllers\[email protected]',
        'method' => 'POST',
        'id' => 'myFormID'
    ]
]) !!}

or this:

{!! Form::open([
    'action' =>  [
        'App\Http\Controllers\[email protected]', 'myFormID'
    ],
    'method' => 'POST'
]) !!}
Activity icon

Replied to How To Specify Attributes In Laravel Collective's Form::open?

Sorry. None of the above works. This works:

{!! Form::open([
    'action' =>  [
        'App\Http\Controllers\[email protected]',
        'method' => 'POST',
        'id' => 'myFormID'
    ]
]) !!}

or this:

{!! Form::open([
    'action' =>  [
        'App\Http\Controllers\[email protected]', 'myFormID'
    ],
    'method' => 'POST'
]) !!}
Oct
21
3 days ago
Activity icon

Replied to Middleware Not Working As Expected

Thanks! It worked! is there any way to avoid checking it at each request through the middleware and instead just log the user out when I press the button to ban them?

Activity icon

Replied to Middleware Not Working As Expected

I do but what if a user gets banned while it's logged in?

Activity icon

Replied to Middleware Not Working As Expected

dd(Auth::guard());
Illuminate\Auth\SessionGuard {#258 ▼
  #name: "web"
  #lastAttempted: null
  #viaRemember: false
  #session: Illuminate\Session\Store {#261 ▶}
  #cookie: Illuminate\Cookie\CookieJar {#262 ▶}
  #request: Illuminate\Http\Request {#43 ▶}
  #events: Illuminate\Events\Dispatcher {#27 ▶}
  #loggedOut: false
  #recallAttempted: false
  #user: null
  #provider: Illuminate\Auth\EloquentUserProvider {#253 ▶}
}
Activity icon

Replied to Middleware Not Working As Expected

dd(auth()->guest());

returns true even if I'm logged in...

Activity icon

Replied to Middleware Not Working As Expected

dd(Auth::check());

returns false

dd(Auth::user());

returns null

Activity icon

Replied to Middleware Not Working As Expected

The fact is that I need it on every request but it would be better to just log the user out as soon as the user is being banned through the User controller. That way I wouldn't need to check each request.

Activity icon

Started a new Conversation Middleware Not Working As Expected

Hello everyone! I have a banned flag in the users table and what I'd like to do is that whenever a user gets banned, it gets disconnected (logged out).

I tried to create a middleware:

php artisan make:middleware LogoutIfBanned

App\Http\LogoutIfBanned.php

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class LogoutIfBanned
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
        if (Auth::check() && Auth::user()->banned) {
            Auth::logout();
            return redirect('/')->with('error', 'You have been banned!');
        }

        return $next($request);
    }
}

and then I added this to App\Http\Kernel.php

protected $middleware = [
    ...
    \App\Http\Middleware\LogoutIfBanned::class
   ...
];

But, still, it doesn't work. I can see the middleware is being loaded but it doesn't disconnect the user when I ban them. What's the issue here?

Also, since this way it's loading the middleware at each request, is there a more efficient way to achieve it?

Oct
15
1 week ago
Activity icon

Replied to Class Parameters Not Taken When Invoked

I can't find this in the official documentation, though.

Activity icon

Started a new Conversation Class Parameters Not Taken When Invoked

So, I'm trying to create a scheduled job by invoking a function.

app/ScheduleObjects/MyClass.php


<?php
    namespace App\ScheduleObjects;
    use \Illuminate\Support\Facades\DB;

    class MyClass
    {
        public function __invoke($x = 10, $y = 20)
        {
            echo "x: " . $x . ", y: " . $y . "\n";
            DB::table('myTable')->where('x', '>', 0)->update(['x' => $x]);
        }
    }
?>

App\Console\Kernel.php

use App\ScheduleObjects\MyClass;
...
protected function schedule(Schedule $schedule)
{
    $schedule->call(new MyClass(40, 50))->everyMinute();
}

The problem is that, while I create the class with x=40 and y=50, it will still display:

x: 10, y: 20

And if I call the class without any default parameters

<?php
    namespace App\ScheduleObjects;
    use \Illuminate\Support\Facades\DB;

    class MyClass
    {
        public function __invoke($x, $y)
        {
            echo "x: " . $x . ", y: " . $y . "\n";
            DB::table('myTable')->where('x', '>', 0)->update(['x' => $x]);
        }
    }
?>

it will not even echo. Why?

Oct
14
1 week ago
Activity icon

Replied to Task Scheduling With An Invokable Object

No problem, thanks anyway! I'm marking my previous answer as best answer, just in case some other person stumbles upon it!

Activity icon

Replied to Task Scheduling With An Invokable Object

So, I found the problem. The problem was that I wasn't passing the $x parameter:

app/ScheduleObjects/myClass.php

<?php
    namespace App\ScheduleObjects;
    use \Illuminate\Support\Facades\DB;

    class myClass
    {
        public function __invoke($x)
        {
            DB::table('myTable')->where('x', '>', 0)->update(['x' => 0]);
        }
    }
?>

Just changing the definition to:

public function __invoke($x = null)

or

public function __invoke()

solved it. Thank you all, anyway, for the help! :)

Activity icon

Replied to Task Scheduling With An Invokable Object

The following works:

Kernel.php

use App\ScheduleObjects\myClass;
...
protected function schedule(Schedule $schedule)
{
    $schedule->call(function () {
        DB::table('myTable')->where('x', '>', 0)->update(['x' => 0]);
    })->everyMinute();
}

So what could the problem be?

Activity icon

Replied to Task Scheduling With An Invokable Object

Thank you! I still don't understand why it doesn't update the DB...

Activity icon

Replied to Task Scheduling With An Invokable Object

I'm running php artisan schedule:run manually.

Output:

Running scheduled command: Closure

Activity icon

Replied to Task Scheduling With An Invokable Object

Alright, so now it's app/ScheduleObjects/myClass.php:

<?php
    namespace App\ScheduleObjects;
    use \Illuminate\Support\Facades\DB;

    class myClass
    {
        public function __invoke($x)
        {
            DB::table('myTable')->where('x', '>', 0)->update(['x' => 0]);
        }
    }
?>

Kernel.php:

use App\ScheduleObjects\myClass;
...
protected function schedule(Schedule $schedule)
{
    $schedule->call(new myClass)->everyMinute();
}

But it still doesn't update the DB...

Activity icon

Replied to Task Scheduling With An Invokable Object

So, I created the file app/ScheduleObjects/test.php:

<?php
    namespace App\ScheduleObjects;
    use \Illuminate\Support\Facades\DB;

    class testClass
    {
        public function __invoke($x)
        {
            DB::table('myTable')->where('x', '>', 0)->update(['x' => 0]);
        }
    }
?>

I updated the classes with composer dump-autoload and I put this inside Kernel.php:

use App\ScheduleObjects\testClass;
...
protected function schedule(Schedule $schedule)
{
    $schedule->call(new testClass)->everyMinute();
}

Then I ran the command php artisan schedule:run:

Running scheduled command: Closure

But, still, the DB doesn't get updated. What am I doing wrong?

Activity icon

Replied to Getting "419 PAGE EXPIRED" In A Modal POST

I just wanted to clarify that it was not Laravel Collective's fault. I made a mistake in my code. :)

Activity icon

Started a new Conversation Task Scheduling With An Invokable Object

So, I was reading about Task scheduling and I was thinking about creating an invokable object and then call it, like the documentation says:

In addition to scheduling using Closures, you may also use invokable objects. Invokable objects are simple PHP classes that contain an __invoke method:

$schedule->call(new DeleteRecentUsers)->daily();

But where, exactly, should I create the invocable obejct?

Oct
13
1 week ago
Activity icon

Replied to Getting "419 PAGE EXPIRED" In A Modal POST

I found the reason. It's because it puts the input after </form>:

<form method="POST" action="..." accept-charset="UTF-8" id="myForm"></form>
<input name="_token" type="hidden" value="...">

But why? I guess it's Laravel Collective's fault?

Activity icon

Replied to Getting "419 PAGE EXPIRED" In A Modal POST

That's it. It doesn't send the token but I can see it in the HTML source.

Activity icon

Started a new Conversation Getting "419 PAGE EXPIRED" In A Modal POST

So, here's thing. If I write a modal like this:

<div class="modal fade" role="dialog">
    <div class="modal-dialog modal-dialog-scrollable" role="document">
        <div class="modal-content">
            <div class="modal-header">
                Title
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>
            {!! Form::open(['action' => [ 'App\Http\Controllers\[email protected]', 'method' => 'POST']]) !!}
            <div class="modal-body">
                ...
                {{Form::submit('Submit')}}
                 {!!Form::close()!!}
            </div>
            <div class="modal-footer">
                ...
            </div>
        </div>
    </div>
</div>

It works. Notice where I put the Form::open (outside the modal-body).

But if I try like this:

<div class="modal fade" role="dialog">
    <div class="modal-dialog modal-dialog-scrollable" role="document">
        <div class="modal-content">
            <div class="modal-header">
                Title
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>
            <div class="modal-body">
                {!! Form::open(['action' => [ 'App\Http\Controllers\[email protected]', 'method' => 'POST'], 'id' => 'myForm']) !!}
                ...
                {{Form::submit('Submit', ['form' => 'myForm'])}}
                 {!!Form::close()!!}
            </div>
            <div class="modal-footer">
                ...
            </div>
        </div>
    </div>
</div>

It will submit the POST request correctly but then I get a 419 - PAGE EXPIRED error. I can see from the source that the CSRF token is being added (automatically by Form::open) in both cases. So what could the problem be?

Activity icon

Replied to How To Specify Attributes In Laravel Collective's Form::open?

I knew someone would've said this! Haha! I'm just curious about it.

Activity icon

Started a new Conversation How To Specify Attributes In Laravel Collective's Form::open?

I would like to specify the id of the form with Laravel Collective. It should turn out to something like:

<form method="..." action="..." id=myFormID">
...

I tried with:

{!! Form::open(['action' => [ 'App\Http\Controllers\[email protected]', 'method' => 'POST'], ['id' => 'myFormID']) !!}

but it doesn't work. The documentation doesn't say anything about it. Any ideas?

Oct
10
2 weeks ago
Activity icon

Replied to Send Form Parameter To A Route Function

Thank you! It worked now!

Activity icon

Replied to Send Form Parameter To A Route Function

Also, I would like to just use $var inside the function, not get it as a form value ($request->input('var')). I mean, just like the store, update or destroy functions work. They get an $id as a parameter and then just it like $id:

public function destroy($id)
{
    return $id;
}
Activity icon

Replied to Send Form Parameter To A Route Function

I tried to define the route as follows:

Route::post('/test/{var}', 'App\Http\Controllers\[email protected]');

Then I submitted the form like this:

...
    $var_to_pass = 'contentofvar';
    {!! Form::open(['action' => [ 'App\Http\Controllers\[email protected]', $var_to_pass ], 'method' => 'POST']) !!}
...

But, still, $request->input('var') is unset inside the function, while the expected behavior is to be redirected to /test/ and use the $var inside the function

public function myFunction(Request $request, $var)
{
    ...
}
Activity icon

Replied to Send Form Parameter To A Route Function

Thanks! Why don't you use Laravel Collective forms? And how would you pass $var_to_pass without using Laravel Collective?

Activity icon

Started a new Conversation Send Form Parameter To A Route Function

Let's suppose I have a Controller myController and I defined a route like this:

Route::post('/test', 'App\Http\Controllers\[email protected]');

And I created the funcion myFunction in the controller, like this:

public function myFunction(Request $request, $var)
{
    ...
}

Now, I create a form that POSTs to that function, something like:

...
    {!! Form::open(['action' => [ 'App\Http\Controllers\[email protected]', $var_to_pass ], 'method' => 'POST']) !!}
...

I would like to pass $var_to_pass to [email protected], but when I try to POST to /test, it will tell me that I only passed one parameter (which is Request $request). How can I make it so that myFunction will also get $var_to_pass as $var?

Oct
08
2 weeks ago
Activity icon

Replied to "required_without" Validation Rule Not Working As Expected

I think I figured out why nullable is still required: because when I leave the textbox image_url empty, it's not null, it's empty. So, while it's still not required because there's the image upload, the validation still sees it as being non-null and thus checks if it's an active url. I guess nullable here means either not set or set to empty.

Activity icon

Replied to "required_without" Validation Rule Not Working As Expected

But still, according to the required without documentation, it shouldn't even check image_url if image_upload is provided...

Activity icon

Replied to "required_without" Validation Rule Not Working As Expected

Thanks for the answer but I still don't understand why sometimes and nullable are necessary. After running some tests, I concluded that this is enough:

$this->validate($request, [
    'image_url' => ['required_without:image_upload', 'nullable', 'active_url'],
    'image_upload' => ['required_without:image_url', 'image'],
]);

Apparently, if you provide an image url, it doesn't check the image upload. So far, so good.

If you provide an image upload, it still checks active_url on the image url and throws an error, since the image_url is present but empty. However, after adding nullable, it goes through and gives no error. No clue why it behaves like this.

Activity icon

Replied to "required_without" Validation Rule Not Working As Expected

Thanks! It works, but why?

The required without documentation states:

required_without:foo,bar,...

The field under validation must be present and not empty only when any of the other specified fields are not present.

So, in this case, image_url must be present and not empty only when image_upload is not present.

What am I missing? Could you please explain it? And why are sometimes and nullable necessary?

Activity icon

Started a new Conversation "required_without" Validation Rule Not Working As Expected

I have a validation like this:

$this->validate($request, [
    'image_url' => ['required_without:image_upload', 'active_url'],
    'image_upload' => ['required_without:image_url', 'image'],
]);

What I would like it to do is that you can either enter an image URL or upload an image. If I enter an image URL, the validation goes through, as expected. However, if I leave the image_url empty and select an image to upload, I get the error message:

The image url is not a valid URL.

Why is this? It shouldn't even check that, because it's not required (since I uploaded an image).

Sep
22
1 month ago
Activity icon

Replied to JS @section Not Being Loaded From Mobile

No clue. The console showed no error!

Activity icon

Replied to JS @section Not Being Loaded From Mobile

Wow. So, now I really feel like a stupid :( Look what the problem was:

before:

var s = n.match(/^[0-9]+(?:.[0-9]+)?$)/);

after:

var s = n.match(/^[0-9]+(?:.[0-9]+)?$/);

A parenthesis..whoa! Thanks anyway for the support!

Activity icon

Replied to JS @section Not Being Loaded From Mobile

I found out by editing that function like this:

function isNumber(n) {
    //var s = n.match(/^[0-9]+(?:.[0-9]+)?$)/);
    //return s ? true : false;
    return true;
}

Well, I cannot see what the error actually is because I don't have access to the console on iOS without a Mac. But on desktop it works well.

Activity icon

Replied to JS @section Not Being Loaded From Mobile

I found the function that's causing trouble. Please read my previous post :)

Activity icon

Replied to JS @section Not Being Loaded From Mobile

Oh, wait! I just found out what's causing the problem! This function is causing some error on mobile and thus all the subsequent code doesn't get executed.

function isNumber(n) {
    var s = n.match(/^[0-9]+(?:.[0-9]+)?$)/);
    return s ? true : false;
}

This function works well on desktop but not on mobile. What's wrong with it?

Activity icon

Replied to JS @section Not Being Loaded From Mobile

Unfortunately, it's not public

Activity icon

Replied to JS @section Not Being Loaded From Mobile

I tried with Safari, FIrefox, Brave and Opera Touch on iOS. All of them don't load it.

Activity icon

Replied to JS @section Not Being Loaded From Mobile

Because it doesn't fetch the new table content from the other page and the data doesn't get updated. Plus, I also tried to put a alert(1); right after the <script> tag and it only displays on web. I really have no clue as to why this happens.

But if I write <script>alert('before');</script> right after @section('js'), it loads it both from desktop and mobile, but it doesn't load the other alert, though.

Activity icon

Started a new Conversation JS @section Not Being Loaded From Mobile

Hello there! I'm having a problem with a Blade template. I have a template one.blade.php, which is something like:

@extends('layouts.adminlte.adminlte')

@section('title')
    My Title 1
@endsection

@section('content')
    @include('two')
@endsection

@section('js')
	<script>
		function checkTableValues() {
			...
		}
		
		function refreshTable(html) {
			...
		}

		...
		
		$(document).ready(function() {
			$(document).on('change','#myTextbox', function () {
                		data = JSON.stringify(myData());
                		$.ajax({
                    			url: '/get_table',
                    			type: 'get',
                    			data: {data: data},
                    			headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
                    			success: function(updated_html){
                        			refreshTable(updated_html);
                        			checkTableValues();
                    			}
                		});
            		});
		});
	</script>
@endsection

@section('css')
	...
@endsection

Then I have two.blade.php which is just returning a .

Now, when I go on https://localhost/one, it loads the view one.blade.php, which, in turn, includes the template two.blade.php (@include('two')) and then, whenever myTextbox gets changed, it retrieves the updated table with the above js form https://localhost/get_table/ (which gets handled by two.blade.php).

The problem is that from desktop everything runs fine, no errors at all. From mobile, the js inside the @section doesn't get loaded and thus it cannot retrieve the updated table from the other page. I don't know what the problem might be and I cannot even debug it from mobile because I'm on iOS and it seems pretty much impossible without having a Mac. Can someone, please, point me to the right direction?