Our Black Friday sale is now live! All individual subscriptions are 50% OFF. This week only!

jeroenvanrensen

jeroenvanrensen

Member Since 6 Months Ago

Utrecht, the Netherlands

Experience Points
53,000
Total
Experience

2,000 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
456
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 11
53,000 XP
Nov
23
1 day ago
Activity icon

Started a new Conversation Laravel Order Query By Other Relationship And Group

Hi everyone,

I have a very complex situation:

I have a table sections and a table pages.

They both have a order column with a number.

A page belongs to a section, or the section_id column is null.

I want to get first all the sections ordered by the order column. And for each section I want to get the pages, also ordered by the order column.

If a page has no section, it should be the first items of the result.

How can I do this in Laravel?

Thank you! Jeroen

What I tried

I tried this:

return Page::orderBy('section_id')
    ->orderBy('title', 'asc')
    ->get()
    ->groupBy('section_id');
Nov
22
2 days ago
Activity icon

Replied to Package Development - Target Class [livewire] Does Not Exist.

@tisuchi I'm creating a package so I cannot use php artisan. Is there another way I can clear the cache?

Nov
21
3 days ago
Activity icon

Started a new Conversation Package Development - Target Class [livewire] Does Not Exist.

Hi everyone,

I'm creating a Laravel package that uses Livewire.

In my browser everything works fine, but my tests fail:

Illuminate\Contracts\Container\BindingResolutionException: Target class [livewire] does not exist.

I have included Livewire in my composer.json:

"require": {
    "livewire/livewire": "^2.3"
},
"require-dev": {
    "orchestra/testbench": "6.0",
    "phpunit/phpunit": "^9.4"
}

And this is my test:

/** @test */
public function a_user_can_visit_the_login_page()
{
    $this->withoutExceptionHandling();
    
    $this->get(route('moon.auth.login'))
        ->assertSeeLivewire('auth.login');
}

Does anyone know what's happening here?

Thank you! Jeroen

Note: In my browser everything works fine, only my tests fail.

Extra code (in case it's useful)

This is my web/routes.php:

use JeroenvanRensen\MoonPHP\Http\Livewire\Auth\Login;

Route::get('/login', Login::class)->name('moon.auth.login');

My Livewire component:

<?php

namespace JeroenvanRensen\MoonPHP\Http\Livewire\Auth;

use Livewire\Component;

class Login extends Component
{
    /**
     * The user's email address.
     *
     * @var string
     */
    public $email;

    /**
     * The user's password.
     *
     * @var string
     */
    public $password;

    /**
     * The validation rules for this component.
     *
     * @var array
     */
    protected $rules = [
        'email' => ['required', 'email', 'max:255'],
        'password' => ['required', 'string', 'min:8']
    ];

    /**
     * Validate the fields when they are updated.
     *
     * @param  string $property
     *
     * @return void
     */
    public function updated($property)
    {
        $this->validateOnly($property);
    }

    /**
     * Try to log the user in.
     * 
     * @return void|\Illuminate\Http\RedirectResponse
     */
    public function login()
    {
        $this->validate();

        $success = auth()->guard('moon')
            ->attempt([
                'email' => $this->email, 
                'password' => $this->password
            ], true);

        if ($success) {
            return redirect()->route('moon.dashboard');
        }

        session()->flash('error', 'These credentials do not match our records.');
    }

    /**
     * Render the component on the page.
     * 
     * @return \Illuminate\Contracts\View\View
     */
    public function render()
    {
        return view('moon::auth.login')
            ->layout('moon::layouts.auth', ['title' => 'Login']);
    }
}
Nov
19
5 days ago
Activity icon

Awarded Best Reply on Suddenly TestCase Class Returns "Class '' Not Found"

@sinnbeck I tried but it does not work.

Finally did a git reset and composer install and now it's working again.

Activity icon

Replied to Suddenly TestCase Class Returns "Class '' Not Found"

@sinnbeck I tried but it does not work.

Finally did a git reset and composer install and now it's working again.

Activity icon

Replied to Suddenly TestCase Class Returns "Class '' Not Found"

@sinnbeck This is the only one:

database/migrations/create_moon_users_table.php

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateMoonUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('moon_users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('moon_users');
    }
}
Activity icon

Replied to Suddenly TestCase Class Returns "Class '' Not Found"

@tisuchi @michaloravec I tried your answers, but neither of them work.

This is my full tests/TestCase.php file:

<?php

namespace JeroenvanRensen\MoonPHP\Tests;

use JeroenvanRensen\MoonPHP\MoonServiceProvider;

abstract class TestCase extends \Orchestra\Testbench\TestCase
{
    protected function setUp(): void
    {
        parent::setUp();
    }

    protected function getPackageProviders($app)
    {
        return [
            MoonServiceProvider::class,
        ];
    }

    protected function getEnvironmentSetUp($app)
    {
        // 
    }
}
Activity icon

Started a new Conversation Suddenly TestCase Class Returns "Class '' Not Found"

Hi everyone,

Suddenly this erros pops up in my tests:

Error: Class '' not found

This is the full error message:

C:\laragon\packages\moonphp-package\vendor\laravel\framework\src\Illuminate\Database\Migrations\Migrator.php:453
C:\laragon\packages\moonphp-package\vendor\laravel\framework\src\Illuminate\Database\Migrations\Migrator.php:189
C:\laragon\packages\moonphp-package\vendor\laravel\framework\src\Illuminate\Database\Migrations\Migrator.php:165
C:\laragon\packages\moonphp-package\vendor\laravel\framework\src\Illuminate\Database\Migrations\Migrator.php:110
C:\laragon\packages\moonphp-package\vendor\laravel\framework\src\Illuminate\Database\Console\Migrations\MigrateCommand.php:85
C:\laragon\packages\moonphp-package\vendor\laravel\framework\src\Illuminate\Database\Migrations\Migrator.php:541
C:\laragon\packages\moonphp-package\vendor\laravel\framework\src\Illuminate\Database\Console\Migrations\MigrateCommand.php:94
C:\laragon\packages\moonphp-package\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:36
C:\laragon\packages\moonphp-package\vendor\laravel\framework\src\Illuminate\Container\Util.php:40
C:\laragon\packages\moonphp-package\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:93
C:\laragon\packages\moonphp-package\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:37
C:\laragon\packages\moonphp-package\vendor\laravel\framework\src\Illuminate\Container\Container.php:596
C:\laragon\packages\moonphp-package\vendor\laravel\framework\src\Illuminate\Console\Command.php:136
C:\laragon\packages\moonphp-package\vendor\symfony\console\Command\Command.php:258
C:\laragon\packages\moonphp-package\vendor\laravel\framework\src\Illuminate\Console\Command.php:121
C:\laragon\packages\moonphp-package\vendor\symfony\console\Application.php:920
C:\laragon\packages\moonphp-package\vendor\symfony\console\Application.php:266
C:\laragon\packages\moonphp-package\vendor\symfony\console\Application.php:142
C:\laragon\packages\moonphp-package\vendor\laravel\framework\src\Illuminate\Console\Application.php:93
C:\laragon\packages\moonphp-package\vendor\laravel\framework\src\Illuminate\Console\Application.php:185
C:\laragon\packages\moonphp-package\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php:263
C:\laragon\packages\moonphp-package\vendor\laravel\framework\src\Illuminate\Testing\PendingCommand.php:194
C:\laragon\packages\moonphp-package\vendor\laravel\framework\src\Illuminate\Testing\PendingCommand.php:348
C:\laragon\packages\moonphp-package\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\InteractsWithConsole.php:59      
C:\laragon\packages\moonphp-package\vendor\laravel\framework\src\Illuminate\Foundation\Testing\RefreshDatabase.php:40
C:\laragon\packages\moonphp-package\vendor\laravel\framework\src\Illuminate\Foundation\Testing\RefreshDatabase.php:17
C:\laragon\packages\moonphp-package\vendor\orchestra\testbench-core\src\Concerns\Testing.php:152
C:\laragon\packages\moonphp-package\vendor\orchestra\testbench-core\src\TestCase.php:65
C:\laragon\packages\moonphp-package\vendor\orchestra\testbench-core\src\Concerns\Testing.php:82
C:\laragon\packages\moonphp-package\vendor\orchestra\testbench-core\src\TestCase.php:43
C:\laragon\packages\moonphp-package\tests\TestCase.php:11

But in my TestCase on line 11 I have this:

public function setUp(): void
{
    parent::setUp(); // line 11
}

So, what can I do about this?

Thank you! Jeroen

Nov
18
6 days ago
Activity icon

Replied to Laravel Autoload Fake Storage Files As Classes

@sinnbeck Yes!!! Thanks for helping me out (again :-))!

Activity icon

Replied to Laravel Autoload Fake Storage Files As Classes

@sinnbeck I want the user to publish a config file, and there all the classes as resources.

Like this:

<?php

use App\Resources\Page;

return [
    'resources' => [
        Page::class
    ]
];
Activity icon

Replied to Laravel Autoload Fake Storage Files As Classes

Hi @sinnbeck,

That's possible too, but how can I get that working?

Currently this is my test:

<?php

namespace JeroenvanRensen\MoonPHP\Tests\Resources;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Storage;
use JeroenvanRensen\MoonPHP\Tests\TestCase;

class ResourceHelpersTest extends TestCase
{
    use RefreshDatabase;

public $model = <<<EOD
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Page extends Model
{
    // 
}
EOD;

public $resource = <<<EOD
<?php

namespace App\Resources;

use JeroenvanRensen\MoonPHP\Resource;
use App\Models\Page;

class Page extends Resource
{
    public $model = PageModel::class;
}
EOD;

    /** @test */
    public function the_resource_class_can_find_all_the_resources()
    {
        $this->withoutExceptionHandling();

        Config::set('filesystems.disks.local.root', app_path());

        Storage::disk('local')->put('Models/Page.php', $this->model);
        Storage::disk('local')->put('Resources/Page.php', $this->resource);

        $resource = \App\Resources\Page;
    }
}

But of course the \App\Resources\Page class is not found.

Nov
17
1 week ago
Activity icon

Started a new Conversation Laravel Autoload Fake Storage Files As Classes

Hi everyone,

I'm creating a package where users can place files in the App\Resources directory.

I want to test if a file there does something.

I'm using the Storage::fake() method for saving classes, but how can I load them?

Thank you! Jeroen

Activity icon

Replied to Laravel Package Session Does Not Save

@sinnbeck Yes that's it! So Laravel applies the web middleware automatically?

Activity icon

Replied to Laravel Package Session Does Not Save

@jlrdw Yes I did, this is my routes/web.php file (in my package folder):

<?php

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Session;

Route::get('/set', function () {
    Session::put('key', 'value');
});

Route::get('/get', function () {
    return Session::get('key');
});

Nov
16
1 week ago
Activity icon

Started a new Conversation Laravel Package Session Does Not Save

Hi everyone,

I'm creating a Laravel Package and I'm using sessions.

This is my routes/web.php file (in my package dir):

Route::get('/set', function () {
    Session::put('key', 'value');
});

Route::get('/get', function () {
    return Session::get('key', 'value');
});

If I browse to /set and next to /get it shows nothing (a blank page).

But this code does work:

Route::get('/get', function () {
    Session::put('key', 'value');
    return Session::get('key', 'value');
});

Note: I'm using the file driver, but with database it works neither.

Does anyone know what's happening here?

Thank you! Jeroen

Activity icon

Replied to Laravel Package Development - Adding An Extra Guard

@rodrigo.pedra Thank you very much! It works!!!

Activity icon

Replied to Laravel Package Development - Adding An Extra Guard

Hi @rodrigo.pedra,

This is currently my providers array in config/app.php:

/*
 * Application Service Providers...
 */
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
JeroenvanRensen\MoonPHP\MoonServiceProvider::class

So it still does not work unfortunately...

Nov
15
1 week ago
Activity icon

Replied to Laravel Package Development - Adding An Extra Guard

Hi @rodrigo.pedra,

Thank you very very very much for your very detailed answer!

I followed all steps, and now I'm understanding how it all works.

Unfortunately, it's not working yet. I can navigate to the login form, but when I hit Submit I get this error:

Auth guard [moon] is not defined. 

Do you know what's happening here?

Maybe there's something wrong in the MoonServiceProvider?

Thank you! Jeroen

Activity icon

Started a new Conversation Laravel Package Development - Adding An Extra Guard

Hi everyone,

I'm creating a package, and I want admins to login using other routes and to have other models and controllers.

I read this article but I don't understand it.

In the docs:

Auth::extend('jwt', function ($app, $name, array $config) {
    // Return an instance of Illuminate\Contracts\Auth\Guard...

   return new JwtGuard(Auth::createUserProvider($config['provider']));
});

Do I have to create a guard class?

And how should my login controller be?

Currently I have this:

<?php

namespace JeroenvanRensen\MoonPHP\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{
    public function show()
    {
        return view('moon::auth.login');
    }

    public function store()
    {
        Auth::guard('moon');

        if (Auth::attempt(['email' => request('email'), 'password' => request('password')])) {
            return redirect('/admin');
        }
        
        return back()->withInput(request()->only('email', 'remember'));
    }
}

But it does not work.

I hope someone can help me out.

Thank you! Jeroen

Nov
14
1 week ago
Activity icon

Awarded Best Reply on Package Development - Factory Not Found

Finally solved it: I forgot to run composer dump-autoload

Activity icon

Replied to Package Development - Factory Not Found

Finally solved it: I forgot to run composer dump-autoload

Nov
13
1 week ago
Activity icon

Replied to Package Development - Factory Not Found

Hi @sinnbeck,

No, this is my composer.json autoload section:

"autoload": {
    "psr-4": {
        "JeroenvanRensen\MoonPHP\": "src",
        "JeroenvanRensen\MoonPHP\Database\Factories\": "database/factories"
    }
}

And it still doesn't work...

Activity icon

Replied to Package Development - Factory Not Found

Hi @sinnbeck,

I did not update composer.

I'm following this tutorial: https://laravelpackage.com/08-models-and-migrations.html#testing-models-and-migrations, and they said I had to do it this way.

What should I change?

Thank you! Jeroen

Activity icon

Replied to Package Development - Factory Not Found

@sinnbeck Okay I updated my post

Activity icon

Started a new Conversation Package Development - Factory Not Found

Hi everyone,

I'm creating a Laravel package, and I have a problem.

I get this message:

Error: Class 'JeroenvanRensen\MoonPHP\Database\Factories\UserFactory' not found

When I run:

php vendor/phpunit/phpunit/phpunit

Some code

This is my test:

tests/Feature/UserTest.php

/** @test */
public function a_user_has_a_name()
{
    $user = User::factory()->create([
        'name' => 'John Doe'
    ]);

    $this->assertEquals('John Doe', $user);
}

This is my factory:

database/factories/UserFactory.php

<?php

namespace JeroenvanRensen\MoonPHP\Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use JeroenvanRensen\MoonPHP\Models\User;

class UserFactory extends Factory
{
    /**
     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = User::class;

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        return [
            'name' => $this->faker->name,
            'email' => $this->faker->unique()->safeEmail,
            'password' => 'yIXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi'
        ];
    }
}

And this is my User model:

src/Models/User.php

class User extends Model
{
    use HasFactory;

    /**
     * Create a new factory instance for the model.
     *
     * @return \JeroenvanRensen\MoonPHP\Database\Factories\UserFactory
     */
    protected static function newFactory()
    {
        return \JeroenvanRensen\MoonPHP\Database\Factories\UserFactory::new();
    }
}

Does anyone know what's happening here?

Thank you! Jeroen

If you need more information, please ask me.

Nov
11
1 week ago
Activity icon

Commented on Constructor Property Promotion

Yeah that's really nice!

Nov
03
3 weeks ago
Activity icon

Replied to Laravel Kahoot Clone: Livewire Or Inertia?

@gitwithravish okay thanks for your answer!

Nov
02
3 weeks ago
Activity icon

Replied to Laravel Kahoot Clone: Livewire Or Inertia?

@gitwithravish okay let me give you a quick description:

Kahoot is a quiz game where people can create and host quizzes. The quiz host shares its screen with all the players.

Other people, the players, can join the quiz using a digital pincode and answer the questions.

So it needs live refreshing.

I hope you understand me. Jeroen

Activity icon

Replied to Laravel Kahoot Clone: Livewire Or Inertia?

Hi @gitwithravish,

Thanks for your detailed answer! Okay, I'm gonna learn both of them.

Do you have a recommendation for this kahoot project? Which of these would you use?

Jeroen

Activity icon

Started a new Conversation Laravel Kahoot Clone: Livewire Or Inertia?

Hi everyone,

I want to create a Kahoot clone using Laravel and I want to learn a new framework.

I read about Laravel Livewire and InertiaJS, but I don't have a good idea of what they are.

So I would like to hear your thoughts: Should I use Livewire or Inertia for a Kahoot clone?

Thank you! Jeroen

Oct
31
3 weeks ago
Activity icon

Replied to VSCode Documentation Block Generator

I get a 404 Not Found error...

Oct
17
1 month ago
Activity icon

Replied to Fake Storage In Another Folder In Laravel

I want to test if it is parsed to a DB row correctly, and if I don’t test it my tests would fail when I change the content.

Activity icon

Started a new Conversation Fake Storage In Another Folder In Laravel

Hi everyone,

I created a folder called posts in my root directory, for all my Markdown files.

I want to parse these to a database table with an artisan command, something like posts:parse.

But how can I fake this directory in PHPunit?

I hope I explained it well, but if you need more information please ask me.

Thank you! Jeroen

Oct
07
1 month ago
Activity icon

Replied to Laravel Artisan - Customize Boiler Template

Hi @snapey,

Yeah that works! Thanks!

Hi @a4ashraf,

I wanted to change the default boiler template to:

<?php

namespace Tests\Unit;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class UserTest extends TestCase
{
    use RefreshDatabase;
}

Jeroen

Activity icon

Replied to Laravel Artisan - Customize Boiler Template

@a4ashraf So I cannot only change the default boiler template?

Activity icon

Started a new Conversation Laravel Artisan - Customize Boiler Template

Hi everyone,

I have a question about Laravel Artisan:

When I run this command:

php artisan make:test UserTest --unit

I get a specific template.

Is there a way how I can change this?

Thank you! Jeroen

Oct
02
1 month ago
Activity icon

Started a new Conversation Pivot Table With Only Created_at Timestamp

Hi everyone,

I'm creating a simple blog and I have got this pivot table migration:

Schema::create('post_tag', function (Blueprint $table) {
    $table->unsignedBigInteger('post_id');
    $table->unsignedBigInteger('tag_id');
    $table->timestamps();
});

But I only want to have a created_at timestamp column, because updated_at makes no sense.

After some searching I found you can implement this in your model, but how can I do this on my pivot table?

Thank you! Jeroen

Sep
28
1 month ago
Activity icon

Started a new Conversation Does PHP Load Classes With Autoloading?

Hi everyone,

Just a small question about PHP.

I found this piece of code on the official PHP Documentation:

spl_autoload_register(function ($class_name) {
    include $class_name . '.php';
});

And I was wondering: does this really import/load all the classes. Or do you have to call use before PHP actually is going to import it?

Because if it does, I guess it would make it really slow.

I would like to hear your answers!

Thank you! Jeroen

Sep
12
2 months ago
Activity icon

Started a new Conversation Laravel Deployment Without CMD Access

Hi everyone,

I just created a laravel application and now I want to deploy it.

However, I don't have access to a terminal / cmd. But I do have access to FTP.

Some ways I thought of

  • Copying all files and create the database in phpMyAdmin based on the migration files
  • Using the PHP's shell_exec() commands

Does anyone know if one of these will work?

And even better, does anyone know of a better method of doing this?

Thank you! Jeroen

Activity icon

Awarded Best Reply on Axios Sends Two Requests

@bobbybouwmann @jlrdw @maverickchan

I finally found the problem

This is my controller code:

<?php

namespace App\Http\Controllers;

use App\Note;

class NoteFavoritesController extends Controller
{
    /**
     * Saves a favorite
     *
     * @param   Note  $note
     *
     * @return  redirect
     */
    public function store(Note $note)
    {
        $this->authorize('update', $note);

        $note->favorite();

        return redirect('/notes/' . $note->id);
    }

    /**
     * Removes a favorite
     *
     * @param   Note  $note
     *
     * @return  redirect
     */
    public function destroy(Note $note)
    {
        $this->authorize('update', $note);
        
        $note->unfavorite();

        return redirect('/notes/' . $note->id);
    }
}

But because of the redirects at the end it does not work. So if I remove them, it does work!

Activity icon

Replied to Axios Sends Two Requests

@bobbybouwmann @jlrdw @maverickchan

I finally found the problem

This is my controller code:

<?php

namespace App\Http\Controllers;

use App\Note;

class NoteFavoritesController extends Controller
{
    /**
     * Saves a favorite
     *
     * @param   Note  $note
     *
     * @return  redirect
     */
    public function store(Note $note)
    {
        $this->authorize('update', $note);

        $note->favorite();

        return redirect('/notes/' . $note->id);
    }

    /**
     * Removes a favorite
     *
     * @param   Note  $note
     *
     * @return  redirect
     */
    public function destroy(Note $note)
    {
        $this->authorize('update', $note);
        
        $note->unfavorite();

        return redirect('/notes/' . $note->id);
    }
}

But because of the redirects at the end it does not work. So if I remove them, it does work!

Sep
08
2 months ago
Activity icon

Started a new Conversation Vue Auth Handling When Session Expires

Hi everyone,

I'm creating an advanced notes app using Laravel and Vue. I use Laravel to login and then redirect to a page where I use VueJS and Axios.

However, if I come back after a while and my session is expired, I can't make Ajax requests anymore, but I also don't get redirected to the login page.

So what can I do about this?

Thank you! Jeroen

Sep
06
2 months ago
Activity icon

Replied to Axios Sends Two Requests

Hi @maverickchan,

I did exactly that but it does not work. Howevery, thanks for your tip.

Jeroen

Sep
03
2 months ago
Activity icon

Replied to Axios Sends Two Requests

Hi @maverickchan,

No, I already tried it and it does not work, unfortunately.

Jeroen

Activity icon

Replied to Axios Sends Two Requests

Hi @maverickchan,

It's working! Now Axios also sends a patch request, but that returns in a 404 error. So the client doesn't notice. It's not perfect, but it works!

Thank you very much! Jeroen