JeroenvanRensen

JeroenvanRensen

Member Since 3 Months Ago

Utrecht, the Netherlands

Experience Points
47,410
Total
Experience

2,590 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
413
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 10
47,410 XP
Sep
12
6 days 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
1 week 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
1 week 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 weeks 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

Activity icon

Replied to Axios Sends Two Requests

@bobbybouwmann sure here you have it.

FavoriteButtonComponent.vue

<template>
    <div>
        <button v-if="favorited" @click="unfavorite"><i class="fas fa-star"></i></button>
        <button v-else @click="favorite"><i class="far fa-star"></i></button>
    </div>
</template>

<script>
    export default {
        props: [
            'note'
        ],

        data() {
            return {
                favorited: false
            }
        },

        methods: {
            favorite() {
                this.favorited = true;

                axios.post('/notes/' + this.note.id + '/favorite');

                this.$root.$emit('refresh');
            },

            unfavorite() {
                this.favorited = false;

                axios.delete('/notes/' + this.note.id + '/favorite');

                this.$root.$emit('refresh');
            }
        },

        mounted() {
            this.favorited = this.note.is_favorited;
        }
    }
</script>

routes/web.php

<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Route::get('/notes', '[email protected]');
Route::post('/notes', '[email protected]');
Route::patch('/notes/{note}', '[email protected]');
Route::delete('/notes/{note}', '[email protected]');

Route::post('/notes/{note}/favorite', '[email protected]');
Route::delete('/notes/{note}/favorite', '[email protected]');

Route::get('/api/notes', '[email protected]');
Route::get('/api/notes/{note}', '[email protected]');

Auth::routes();

Route::get('/home', '[email protected]')->name('home');

NoteController.php

<?php

namespace App\Http\Controllers;

use App\Note;
use Carbon\Carbon;

class NoteController extends Controller
{
    /**
     * Only authenticated users can use this controller
     *
     * @return  void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Returns all the notes of the authenticated user
     *
     * @return  array
     */
    public function index()
    {
        $notes = \App\Note::where('user_id', auth()->id());

        if(request()->has('favorites')) {
            $notes = $notes->where('is_favorited', true);
        }
        
        if(request()->has('trash')) {
            $notes = $notes->onlyTrashed();
        }

        if(request()->has('query')) {
            $notes = $notes->where('title', 'like', '%' . request('query') . '%');
        }

        $notes = $notes->orderBy('updated_at', 'desc')->get();

        return $notes;
    }

    /**
     * Returns an empty page
     *
     * @return  view
     */
    public function show()
    {
        $this->permanentlyDeleteNotes();

        return view('notes.show');
    }

    /**
     * Creates a new note
     *
     * @return  void
     */
    public function store()
    {
        $note = Note::create([
            'title' => $this->setTitle(''),
            'user_id' => auth()->id()
        ]);

        return $note->id;
    }

    /**
     * Returns the note in an edit form
     *
     * @param   Note  $note
     *
     * @return  view
     */
    public function edit(Note $note)
    {
        $this->authorize('update', $note);

        if($note->trashed()) {
            $note->restore();
        }

        return $note;
    }

    /**
     * Saves the edited note
     *
     * @param   Note  $note
     *
     * @return  void
     */
    public function update(Note $note)
    {
        $this->authorize('update', $note);

        $note->update([
            'title' => $this->setTitle(request('body')),
            'body' => request('body')
        ]);
    }

    /**
     * Deletes a note
     *
     * @param   Note  $note
     *
     * @return  void
     */
    public function destroy(Note $note)
    {
        $this->authorize('update', $note);

        $note->delete();
    }

    /**
     * Generates a title based on the body
     *
     * @param   string  $body
     *
     * @return  string
     */
    protected function setTitle($body)
    {
        if($title = strtok($body, "\n")) {
            return preg_replace('/^[ #]+/', '', $title);
        }
        
        return 'Untitled';
    }

    protected function permanentlyDeleteNotes()
    {
        Note::withTrashed()
            ->where('deleted_at', '<', Carbon::now()->subMonth())
            ->forceDelete();
    }
}
Sep
02
2 weeks ago
Activity icon

Replied to Axios Sends Two Requests

@bobbybouwmann @jlrdw @maverickchan Does anyone know how to solve this?

Activity icon

Replied to Axios Sends Two Requests

Yes I did but it doesn't change...

Sep
01
2 weeks ago
Activity icon

Replied to Axios Sends Two Requests

Hi @maverickchan,

I changed it but it doesn't fix it, which makes sense actually, because Laravel makes difference between post and delete requests.

However, thanks for trying to help me!

Aug
31
2 weeks ago
Activity icon

Replied to Axios Sends Two Requests

Hi @maverickchan,

I do not use the api.php, because I don't know how it works.

You said you saw a conflicting route? Can you tell me more about that?

Thank you! Jeroen

Activity icon

Replied to Axios Sends Two Requests

Note: If I remove the axios delete request from the FavoriteButtonComponent, the note does not get deleted. So the problem is some where in that component.

Activity icon

Replied to Axios Sends Two Requests

Hi @jlrdw how do you mean check the naming?

@maverickchan I don't use Vue Routing, but Laravel Routing.

These are my routes:

Route::get('/', function () {
    return view('welcome');
});

Route::get('/notes', '[email protected]');
Route::post('/notes', '[email protected]');
Route::patch('/notes/{note}', '[email protected]');
Route::delete('/notes/{note}', '[email protected]');

Route::post('/notes/{note}/favorite', 'NoteFavorites[email protected]');
Route::delete('/notes/{note}/favorite', '[email protected]');

Route::get('/api/notes', '[email protected]');
Route::get('/api/notes/{note}', '[email protected]');

Auth::routes();

Route::get('/home', '[email protected]')->name('home');
Aug
30
2 weeks ago
Activity icon

Replied to Using Pivot Table For Tables That Relate To Each Other

Hola!

I'm Jeroen, learning Spanish.

However, In the question table I don't see an exam_id column. If you do have it then I guess you simply can the questions function in your exam model lile this:

return $this->hasMany(Question::class);
Activity icon

Replied to How Can Remake This Laravel Blade.php Code In Vue ?

I guess something like this:

<template>
    
</template>

<script>
    export default {
        data() {
            return {
                i: 0
            }
        },

        mounted() {
            first() {
                return i % 2 ? 'first' : '';
            },

            second() {
                return i % 2 ? '' : 'second';
            }
        },

        created() {
            this.i++;
        }
    }
</script>
Activity icon

Replied to Axios Sends Two Requests

@bobbybouwmann but if I remove that component I still have the same problem.

Activity icon

Replied to Axios Sends Two Requests

@bobbybouwmann this is the only one, DeleteButtonComponent, but I do not see any reason why it would happen.

<template>
    <div>
        <button @click="deleteNote"><i class="fas fa-trash-alt"></i></button>
    </div>
</template>

<script>
    export default {
        props: [
            'id'
        ],

        methods: {
            deleteNote() {
                axios.delete('/notes/' + this.id)
                    .then(function() {
                        this.$root.$emit('emptyNote');
                        this.$root.$emit('refresh');
                    }.bind(this));
            }
        }
    }
</script>
Activity icon

Replied to Axios Sends Two Requests

@bobbybouwmann yes, of course!

Here's my full FavoriteButtonComponent:

<template>
    <div>
        <button v-if="favorited" @click="unfavorite"><i class="fas fa-star"></i></button>
        <button v-else @click="favorite"><i class="far fa-star"></i></button>
    </div>
</template>

<script>
    export default {
        props: [
            'note'
        ],

        data() {
            return {
                favorited: false
            }
        },

        methods: {
            favorite() {
                this.favorited = true;

                axios.post('/notes/' + this.note.id + '/favorite');
            },

            unfavorite() {
                this.favorited = false;

                axios.delete('/notes/' + this.note.id + '/favorite');
            }
        },

        mounted() {
            this.favorited = this.note.is_favorited;
        }
    }
</script>
Activity icon

Started a new Conversation Axios Sends Two Requests

Hi everyone,

I've got this code:

axios.delete('/notes/' + this.note.id + '/favorite');

But if I inspect my network tab, I see these two requests:

delete: http://notes.local/notes/4/favorite
delete: http://notes.local/notes/4

So, my note will be deleted too. What can I do about this?

Thank you! Jeroen

Note: by the favorite post request I do have the same problem, but then I get a 404 error, so it's not a problem.

Aug
26
3 weeks ago
Activity icon

Started a new Conversation OctoberCMS - Taglist Form Widget In Relation Mode With Several Extra Fields

Hello,

I use the taglist form widget in relation mode in order to add some tags to a model in a many to many relation.

Works great when my tag model only have 1 required title field, but I want to add slug to it (required too). It works perfectly when I create my tag manually, but I also want to be able to add tags using the taglist form widget with an auto generating slug.

Now I have 2 required fields "title" and "slug", when I try to add a tag using the taglist, I get an error saying that "the slug field is required".

Sounds logical as I created that secondary field and set up the field as required, but how can I continue to add tags to my taglist ? Normally the slug field have a preset based on the title, but it only works when I add tag using the "core" tag form, not when I create them with taglist.

Aug
09
1 month ago
Activity icon

Started a new Conversation JS - Reg Ex New Value In Str Replace

Hi everyone,

I have got a problem with Regular Expressions. I do have this string:

https://nl.wikipedia.org/wiki/Republikeinwever

And I want to change it to this:

https://nl.m.wikipedia.org/wiki/Republikeinwever

But, nl and Republikeinwever can change, and it should still work.

So this:

https://en.wikipedia.org/wiki/World_War_II

Should become this:

https://en.m.wikipedia.org/wiki/World_War_II

How can I do this in pure JS?

I tried to do it with Regular Expressions, but couldn't solve it.

Something like this?

var newValue = oldValue.replace(
    /https:\/\/([a-z]+).wikipedia.org\/wiki\/([A-Za-z]+)/i,
    https://.m.wikipedia.org/wiki/
);

I hope anyone can help me.

Thanks!

Aug
02
1 month ago
Activity icon

Started a new Conversation Tinker: "Call To A Member Function Tags() On Null" But PHPunit Does Work

Hi everyone,

I am testing my code in Tinker, after it worked in PHPunit. In tinker I got the following error:

PHP Error:  Call to a member function tags() on null in C:/wamp64/www/laravel/sahara/app/Bookmark.php on line 53

Ater trying this command:

$bookmark = App\Bookmark::first();
$bookmark->addTag('bootstrap');

And this is my addTag() method in my Bookmark model:

/**
 * Add a tag to the bookmark based on a string
 * 
 * 1. If the tag already exists on the bookmark, return
 * 2. If the tag doesn't exist, create it
 * 3. Attach the tag to the bookmark
 * 
 * @param   string  $tag
 * 
 * @return  null
 */
public function addTag($tag)
{
    if($this->tags()->where('name', $tag)->exists()) {
        return; 
    }

    if(auth()->user()->tags()->where('name', $tag)->exists()) {
        $tag = auth()->user()->tags()->where('name', $tag)->first();
    } else {
        $tag = Tag::create([
            'name' => $tag,
            'slug' => $tag,
            'user_id' => auth()->id()         
        ]);
    }

    $this->tags()->attach($tag);
}

Howevery, the tags relation does exist in my Bookmark model:

/**
 * Returns all the tags which a bookmark does have
 * 
 * @return  App\Tag[]
 */
public function tags()
{
    return $this->belongsToMany(Tag::class, 'bookmark_tags');
}

Note: I did not forget to run my migrations.

So, whats going on here?

I hope anyone can help me.

Thank you! Jeroen

Jul
20
1 month ago
Activity icon

Replied to Laravel File Storage - Deleting Files Doesn't Work (also No Error Provided)

Hi @mabdullahsari and @chr15k,

Your methods didn't work for me, so I've made it so it only delete the relationship.

Once per month I can delete all files using a cron job.

However, thanks for your answers!

Jul
19
1 month ago
Activity icon

Started a new Conversation Anchor Tag Not Showing

Hi everyone,

I've got a crazy problem here:

I've got an anchor tag in my database which I'm showing with VueJS. Directly before it I manually create an anchor link:

<div><a href="#">Link</a> {{ body }}</div>

However, I got this on my page:

My BS Card

And this is what I see in Firefox Devtools:

Firefox Devtools

Can anyone see and tell me what I'm doing wrong? Maybe Vue doesn't allow you to get anchor links out of the database, but then I guess I should see anything else in my Devtools.

Activity icon

Started a new Conversation Laravel ShouldReceive Method Not Found, And What Is It?

Hi everyone,

I'm following a Laracasts tutorial (Build a stock tracker app) and I've got the following problem:

I don't know what the shouldReceive method is and what it should do, but I got this error:

Error: Call to undefined method App\Clients\ClientFactory::shouldReceive()

I have imported the ClientFactory, and here are some things that maybe went wrong:

  • The ClientFactory does not have a shouldReceive method
  • The ClientFactory does not extend or implement another class

Here's some code:

StockTest

/** @test */
public function it_updates_local_stock_status_after_being_tracked()
{
    $this->withoutExceptionHandling();
    
    $this->seed(\RetailerWithProductSeeder::class);

    ClientFactory::shouldReceive('make')->andReturn(new FakeClient);

    $stock = Stock::first()->track();

    $this->assertTrue($stock->in_stock);
    $this->assertEquals(9900, $stock->price);
}

ClientFactory

<?php

namespace App\Clients;

use App\Retailer;

class ClientFactory
{
    public function make(Retailer $retailer): Client
    {
        $classname = \Str::studly($retailer->name);
        $class = 'App\Clients\'.$classname;
    
        if(!class_exists($class)) {
            throw new ClientException('Client not found for '.$retailer->name);
        }
    
        return new $class;
    }
}

I really don't know what the shouldReceive method does and how to fix this problem.

I hope anyone else can help me.

Thank you! Jeroen

Jul
18
2 months ago
Activity icon

Replied to Laravel Database Seeding Class Not Found

Hi @bezhansalleh,

I tried your code and it's finally working, so thanks!

I don't see a spelling mistake, I only see the imports I seems to be forgotten.

Do you know why I didn't get a more specific error?

Thank you! Jeroen

Activity icon

Replied to Laravel Database Seeding Class Not Found

Hi @gamerfac3, @bezhansalleh,

I changed the name and ran this command:

php artisan db:seed --class=RetialerWithProductSeeder

Now I got this error:

   Illuminate\Contracts\Container\BindingResolutionException

  Target class [RetialerWithProductSeeder] does not exist.

  at C:\wamp64\www\laravel\stock-tracker\vendor\laravel\framework\src\Illuminate\Container\Container.php:807
    803|
    804|         try {
    805|             $reflector = new ReflectionClass($concrete);
    806|         } catch (ReflectionException $e) {
  > 807|             throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
    808|         }
    809|
    810|         // If the type is not instantiable, the developer is attempting to resolve
    811|         // an abstract type such as an Interface or Abstract Class and there is

  1   C:\wamp64\www\laravel\stock-tracker\vendor\laravel\framework\src\Illuminate\Container\Container.php:805
      ReflectionException::("Class RetialerWithProductSeeder does not exist")

  2   C:\wamp64\www\laravel\stock-tracker\vendor\laravel\framework\src\Illuminate\Container\Container.php:805
      ReflectionClass::__construct("RetialerWithProductSeeder")

I really don't know what to do here.

Activity icon

Replied to Laravel Database Seeding Class Not Found

I tried it and it changed the error:

ErrorException: include(C:\wamp64\www\laravel\stock-tracker\vendor\composer/../../database/seeds/RetailerWithProduct.php): failed to open stream: No such file or directory
Activity icon

Started a new Conversation Laravel Database Seeding Class Not Found

Hi everyone,

I've got a database seeder class, which I want to use in my PHPunit test. However, I got this message: Target class [database\seeds\RetailerWithProduct] does not exist.

This is my Database Seeder

<?php

use Illuminate\Database\Seeder;

class RetailerWithProduct extends Seeder
{
    public function run()
    {
        $product = Product::create([
            'name' => 'Nintendo Switch'
        ]);

        $retailer = Retailer::create([
            'name' => 'Best Buy'
        ]);

        $stock = new Stock([
            'price' => 10000,
            'url' => 'https://www.example.org/',
            'sku' => 12345,
            'in_stock' => false
        ]);

        $retailer->addStock($product, $stock);
    }
}

And here's my PHPunit test:

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

    $this->seed(RetailerWithProduct::class);

    dd(Product::all());

    $this->assertFalse($stock->fresh()->in_stock);

    Http::fake(function() {
        return [
            'available' => true,
            'price' => 29900
        ];
    });

    $this->artisan('stock:track');

    $this->assertTrue($stock->fresh()->in_stock);
}

Two things are getting my attention:

  • I do not import the Database Seeder in my test
  • The Database Seeder doens't have a namespace

But I'm watching a Laracasts series and Jeffrey also doesn't one of these.

I think I have everything the same, but why do I get this error?

Thank you! Jeroen

If you need more information, please ask me.

PS: I also ran composer dump-autoload

Activity icon

Started a new Conversation Laravel Custom Validation Uses Validate Function Instead Of Passes

Hi everyone,

I've got a problem: I'm creating custom validation methods, but I have to use a validate() and a passes() method, but I should only have to use the passes() function.

If I remove one of them, it fails. I got an error or it passes without the proper validation.

What could be the problem?

Thank you! Jeroen

Jul
16
2 months ago
Activity icon

Replied to Laravel File Storage - Deleting Files Doesn't Work (also No Error Provided)

Hi @mabdullahsari,

No I haven't, but it's still not fixed.

I ran this command:

C:\wamp64\www\laravel\wauwcloset>php artisan storage:link

And got this output (in green):

The [C:\wamp64\www\laravel\wauwcloset\public\storage] link has been connected to [C:\wamp64\www\laravel\wauwcloset\storage\app/public].
The links have been created.

But I think nothing has changed.

I really hope you can help me.

Thank you! Jeroen

Activity icon

Replied to Laravel Notifications - Exists In Database, But Not In Auth()->user()->notifications

@manelgavalda Thank you so mush! I completely forgot about that! Thanks!

Activity icon

Started a new Conversation Laravel Notifications - Exists In Database, But Not In Auth()->user()->notifications

Hi everyone,

I've got a strange problem, and I'm trying to fix it for an hour now, but I give up. I hope anyone else can help me.

This is my TDD test:

/** @test */
public function a_subscribed_user_gets_a_notification_by_a_new_reply()
{
    $this->withoutExceptionHandling();
    
    $user1 = factory('App\User')->create(); // User who leaves the reply
    $user2 = factory('App\User')->create(); // User who subscribes and gets notified

    $thread = factory('App\Thread')->create();

    // User 2: User who subscribes and gets notified
    $this->actingAs($user2);

    $thread->subscribe();

    $this->assertCount(0, auth()->user()->notifications);

    // User 1: User who leaves the reply
    $this->actingAs($user1);

    $reply = factory('App\Reply')->make([
        'thread_id' => $thread->id
    ]);

    $this->post($thread->path().'/replies', $reply->toArray())
        ->assertStatus(302);

    // User 2: User who subscribes and gets notified
    $this->actingAs($user2);

    $this->assertDatabaseHas('notifications', [
        'type' => 'App\Notifications\ThreadWasUpdated',
        'notifiable_id' => $user2->id,
        'notifiable_type' => 'App\User'
    ]);

    $this->assertCount(1, auth()->user()->notifications); // not working
}

I know, little bit complex, but it should work. And it does, except for the last assertion. So the row does exist in the database (as you can see) but I can't get the user notifications.

Does anyone know what I'm doing wrong?

Also, in the browser it also works completely fine.

I really hope someone can help me out.

Thank you! Jeroen

Jul
15
2 months ago
Activity icon

Replied to Do You Move Controller Methods To Models Or Not?

Hi @tisuchi @deepu07 @jeffreyvanrossum @mabdullahsari @jlrdw @snapey @bugsysha @martinbean,

Thanks for all of your answers! Like I read, it's better to move it to models. So I'm trying to do that. There are still some situations it feels "strange" for me, like the given example.

But for example I do like this method: $thread->subscribe($user).

Like I said, I'm gonna try to do it more often.

Again, thanks for all of your answers!

Jeroen

Activity icon

Awarded Best Reply on Laravel TDD - Attribute [store] Does Not Exist

It turned out: I made a mistake:

Route::store('/threads/{category}/{thread}/subscriptions', '[email protected]');

So, that's quite stupid...

Activity icon

Replied to Laravel TDD - Attribute [store] Does Not Exist

It turned out: I made a mistake:

Route::store('/threads/{category}/{thread}/subscriptions', '[email protected]');

So, that's quite stupid...

Activity icon

Replied to Laravel TDD - Attribute [store] Does Not Exist

Hi @jeffreyvanrossum,

I did some research and it turned out I always got that error, even in this test:

* @test */
public function one_equals_one()
{
    $this->withoutExceptionHandling();
    
    $this->assertEquals(1, 1);
}
Activity icon

Started a new Conversation Laravel TDD - Attribute [store] Does Not Exist

Hi everyone,

I'm creating a website with Laravel using TDD. I've got the following error:

Attribute [store] does not exist

Using this test:

* @test */
public function one_equals_one()
{
    $this->withoutExceptionHandling();
    
    $this->assertEquals(1, 1);
}

So what's going on here?

What can I do?

I searched on Google but couldn't find anything.

Thank you! Jeroen

Jul
14
2 months ago
Activity icon

Started a new Conversation Do You Move Controller Methods To Models Or Not?

Hi everyone,

I'm watching a lot of Laracasts series, and something I noticed was that Jeffrey moves a lot of his controller actions to models.

For example ReplyController:

public function store(Thread $thread) 
{
    request()->validate([
        'body' => ['required']
    ]);

    return $thread->addReply([
        'body' => request('body'),
        'user_id' => auth()->id()
    ]);
}

And Thread.php:

public function addReply($reply)
{
    $reply = $this->replies()->create($reply);

    event(new ThreadReceivedNewReply($reply));

    return $reply;
}

However, I personally prefer to do it this way:

ReplyController.php

public function store(Thread $thread)
    request()->validate([
        'body' => ['required']
    ]);

    $reply = $thread->replies()->create([
        'user_id' => auth()->id(),
        'thread_id' => $thread->id,
        'body' => request('body')
    ]);
}

What do you think, and what are your preferences?

I like to hear your thoughts.

Thank you! Jeroen

Jul
13
2 months ago
Activity icon

Awarded Best Reply on VueJS - Error Compiling Template: The Value For A V-bind Expression Cannot Be Empty. Found In "v-bind:data"

I found the problem: I was paginating the replies on the PHP end...

Activity icon

Replied to VueJS - Error Compiling Template: The Value For A V-bind Expression Cannot Be Empty. Found In "v-bind:data"

I found the problem: I was paginating the replies on the PHP end...

Activity icon

Started a new Conversation VueJS - Error Compiling Template: The Value For A V-bind Expression Cannot Be Empty. Found In "v-bind:data"

Hi everyone,

I've got a strange error:

[Vue warn]: Error compiling template:

The value for a v-bind expression cannot be empty. Found in "v-bind:data"

1  |  <div id="app">
   |  ^^^^^^^^^^^^^^
2  |          <nav class="navbar navbar-expand-lg navbar-light mb-5">
   |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3  |              <div class="container">
   |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4  |                  <a class="navbar-brand" href="/">Laravel Forum</a>
   |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5  |          
   |  ^^^^^^^^
6  |                  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarContent">
   |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7  |                      <span class="navbar-toggler-icon"></span>
   |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8  |                  </button>
   |  ^^^^^^^^^^^^^^^^^^^^^^^^^

But in my navbar I don't use Vue, so what's going on here?

I also don't see a line number of the error, and npm run watch ran successful.

What can I do?

Thank you! Jeroen

If you need more information, please ask me.

Activity icon

Awarded Best Reply on Vue Method Not Found, But It Does Exist

Update

I found the problem, I just forgot to run npm run watch...

Activity icon

Replied to Vue Method Not Found, But It Does Exist

Update

I found the problem, I just forgot to run npm run watch...

Activity icon

Started a new Conversation Vue Method Not Found, But It Does Exist

Hi everyone,

I've got a strange situation: I get this error in my console:

[Vue warn]: Property or method "destroy" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

But I do have the method registred here, in ReplyComponent:

<script>
    export default {
        props: [
            'attributes',
            'path'
        ],

        data() {
            return {
                editing: false,
                body: this.attributes.body
            }
        },

        methods: {
            update() {
                axios.patch(this.path, {
                    body: this.body
                });

                this.editing = false;

                toast('Your reply has been updated!');
            },

            destroy() {
                console.log('delete');
            }
        }
    }
</script>

And here I'm calling it:

@can('update', $reply)
    <button class="btn btn-light" @click="editing = true"><i class="text-primary fas fa-pencil-alt"></i></button>
@endcan

@can('delete', $reply)
    <button class="btn btn-light" @click="destroy"><i class="text-danger fas fa-trash-alt"></i></button>
@endcan

As you can see, I also have a editing method which works completely fine.

So what's the problem here?

Thank you! Jeroen