janmoes

Member Since 2 Years Ago

Experience Points
4,020
Total
Experience

980 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
21
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.

  • Community Pillar

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

Level 1
4,020 XP
Mar
23
3 weeks ago
Activity icon

Replied to Laravel Policies, Can I Check Other Behavior Instead Of Authentication?

Okay, yeah I get that since it's important to organize my code for readability. So ?User $authUser surely makes it not required to use that parameter?

Activity icon

Replied to Laravel Policies, Can I Check Other Behavior Instead Of Authentication?

So something like

public function view(?User $authUser, User $user, Site $site){
	return $user->id === $site->user_id;
}
Activity icon

Replied to Laravel Policies, Can I Check Other Behavior Instead Of Authentication?

Hmm so in my case return $user->id ==== $site->user_id? And is that being validated in my controller or policy?

Activity icon

Replied to Laravel Policies, Can I Check Other Behavior Instead Of Authentication?

I've already did put checks like this in my controller methods

public function show(User $user, Site $site)
    {
        // Check if site belongs to user.
        if ($site->user->isNot($user)){
            abort(404);
        }
        // dd($user, $site);
        return view('sites.show', ['user' => $user, 'site' => $site]);
    }

It works, but it doesn't seem ideal, so I was wondering if this kind of check could be done in policies. Again, this has nothing to do with authenticated users!

Activity icon

Started a new Conversation Laravel Policies, Can I Check Other Behavior Instead Of Authentication?

Hey there, I've been using policies for a while now, to check if the authenticated user belongs to a site model. Which works fine.

Now here's the thing. I've made a nested resource controller for sites. That means that when you go to users/1/sites/1 you would see the user with id 1 and his site with id 1. A site can only be owned by a specific user, so I checked that by browsing to users/2/sites/1 which prints the data for user 2 but still the site which is owned by user 1. I thought nested resource controllers would do some Laravel magic to fix that, but no.

So my question is, are Policies, also meant for checking if a user and a site belong to eachother without the user being authenticated? So that a user id in the url can only match with a site id in the url and otherwise would abort a 404?

Mar
02
1 month ago
Activity icon

Replied to Livewire Not Updating A Value

I've got it kinda working now. The Domain list loads, and when I click on the increment/decrement button an error screen pops up with: ```Trying to get property 'id' of non-object (View: D:\wamp64\www\webprepare_dashboard\resources\views\livewire\domain-list.blade.php)` ``

//Component
class DomainList extends Component
{
    public $base_url = 'https://my.gridpane.com/oauth/api/v1/site?page=';
    public $page_number = 1;
    public $domains;
    public $first_page;
    public $last_page;
    public $prev = true;
    public $next = true;

    public function mount(){
        $response = Http::withOptions([ //use this method
            'verify'     => false, //This key and value in this method
        ])->withHeaders([
            'Content-Type'  => 'application/json',
            'Accept'        => 'application/json',
            'Authorization' => 'Bearer '.env('GRIDPANE_BEARER_TOKEN'),
            'data-raw'      =>  [
                'summary' => true,
            ],
        ])->get($this->base_url.$this->page_number);
        
        
        $this->first_page = $response['links']['first'];
        $this->last_page = $response['links']['last'];
        $this->domains = collect($response['data'])->map(fn($domain) => (object) $domain);
        // dd($this->domains);
    }

    public function increment(){
        $this->page_number++;
        // dd($this->page_number);
    }

    public function decrement(){
        $this->page_number--;
    }

    public function render()
    {
        return view('livewire.domain-list')->extends('layouts.app');
    }
}
//View from component
<div> 
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-10">
                <div class="card">
                    <div class="card-header">{{ __('Dashboard') }}</div>

                    <div class="card-body">
                        <h2 class="text-center">Domeinen</h2>
                        <div class="table-responsive">
                            <table class="table">
                                <thead>
                                    <tr>
                                        <th scope="col">ID</th>
                                        <th scope="col">Naam</th>
                                        <th scope="col">Opties</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach($domains as $domain)
                                    <tr>
                                        <th scope="row">{{$domain->id}}</th>
                                        <td>{{$domain->url}}</td>
                                        <td><a href="{{ route('domains.show', $domain->id) }}" class="btn btn-primary btn-font"><i class="fa fa-globe"></i> Bekijk domein details</a></td>
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                        <div>
                            <span>{{$page_number}}</span>
                            <button class="btn btn-success" wire:click="decrement">-</button>
                            <button class="btn btn-success" wire:click="increment">+</button>
                        </div>
                        <a href="{{ route('home') }}" class="btn btn-warning"><i class="fa fa-arrow-left"></i> Terug naar het dashboard</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
</div>



Activity icon

Replied to Livewire Not Updating A Value

I think I've come a little further. I know get the error Undefined index: links but when I dd() the code it works fine:

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use Illuminate\Support\Facades\Http;

class DomainList extends Component
{
    public $base_url = 'https://my.gridpane.com/oauth/api/v1/site?page=';
    public $page_number = 1;
    public $domains = [];
    public $first_page;
    public $last_page;
    public $prev = true;
    public $next = true;

    public function mount(){
        $response = Http::withOptions([ //use this method
            'verify'     => false, //This key and value in this method
        ])->withHeaders([
            'Content-Type'  => 'application/json',
            'Accept'        => 'application/json',
            'Authorization' => 'Bearer '.env('GRIDPANE_BEARER_TOKEN'),
            'data-raw'      =>  [
                'summary' => true,
            ],
        ])->get($this->base_url.$this->page_number);
        
        
        $this->first_page = $response['links']['first'];
        $this->last_page = $response['links']['last'];
        $this->domains = collect($response['data'])->map(fn($domain) => (object) $domain);
        // dd($this->domains);
    }

    public function increment(){
        $this->page_number++;
        // dd($this->page_number);
    }

    public function decrement(){
        $this->page_number--;
    }

    public function render()
    {
        return view('livewire.domain-list')
        ->extends('layouts.app');
    }
}

Activity icon

Replied to Livewire Not Updating A Value

I appreciate your help! I remember earlier today that when I had like a plain component template that it worked. But since I've added everything it stopped working ;(

Activity icon

Replied to Livewire Not Updating A Value

<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>{{ config('app.name', 'Laravel') }}</title>

    <!-- Scripts -->
    <script src="{{ asset('js/app.js') }}" defer></script>

    <!-- Fonts -->
    <link rel="dns-prefetch" href="//fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">

    <!-- Styles -->
    <link href="{{ asset('css/app.css') }}" rel="stylesheet">
    @livewireStyles
</head>
<body>
    <div id="app">
        <nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm">
            <div class="container">
                <a class="navbar-brand" href="{{ url('/') }}">
                    <svg width="100" height="50">
                    <img src="{{ asset('img/webprepare.svg') }}"><!--{{ config('app.name', 'Webprepare dashboard') }}-->
                    </svg>
                </a>
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
                    <span class="navbar-toggler-icon"></span>
                </button>

                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <!-- Left Side Of Navbar -->
                    <ul class="navbar-nav mr-auto">

                    </ul>

                    <!-- Right Side Of Navbar -->
                    <ul class="navbar-nav ml-auto">
                        <!-- Authentication Links -->
                        @guest
                            <li class="nav-item">
                                <a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
                            </li>
                            @if (Route::has('register'))
                                <li class="nav-item">
                                    <a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
                                </li>
                            @endif
                        @else
                            <li class="nav-item dropdown">
                                <a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
                                    {{ Auth::user()->name }}
                                </a>

                                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
                                    <a class="dropdown-item" href="{{ route('logout') }}"
                                       onclick="event.preventDefault();
                                                     document.getElementById('logout-form').submit();">
                                        {{ __('Logout') }}
                                    </a>

                                    <form id="logout-form" action="{{ route('logout') }}" method="POST" class="d-none">
                                        @csrf
                                    </form>
                                </div>
                            </li>
                        @endguest
                    </ul>
                </div>
            </div>
        </nav>

        <main class="py-4">
            @yield('content')
        </main>
    </div>
    @livewireScripts
</body>
</html>
``` Here you go :)
Activity icon

Replied to Livewire Not Updating A Value

Nope It still doesn't work. Since I have an empty div around all the other html I'm not sure what is going wrong

Activity icon

Replied to Livewire Not Updating A Value

Nope already had that in the first place :(

Activity icon

Replied to Livewire Not Updating A Value

I have the Yield directive in my app.blade.php and @section('content') in the blade file from my component, i've also added that ->section('content') but still nothing :(

Activity icon

Replied to Livewire Not Updating A Value

is also a but in font-weight; bold :)
Activity icon

Replied to Livewire Not Updating A Value

I've added the style and script tags from livewire into the layouts/app.blade.php and executed the artisan command, but it still doesn't work :(

Activity icon

Replied to Livewire Not Updating A Value

If I remove everything except for only an empty div with those two buttons it works. But I need the entire html :'(

Activity icon

Replied to Livewire Not Updating A Value

I haven't tested the other functions yet. I've started simple. If I can make those easy functions work, I'm sure I can figure the rest out too ;)

Activity icon

Replied to Livewire Not Updating A Value

Nope also nothing :(

Activity icon

Replied to Livewire Not Updating A Value

Nope, that's why I usually use dd() to check if something even reaches the function.

Activity icon

Replied to Livewire Not Updating A Value

@chaudigv Thanks for the reply! I've added the extending to the view render, and changed the view from the component to this:

<div>
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-10">
            <div class="card">
                <div class="card-header">{{ __('Dashboard') }}</div>

                <div class="card-body">
                    <h2 class="text-center">Domeinen</h2>
                    <div class="table-responsive">
                        <table class="table">
                            <thead>
                                <tr>
                                    <th scope="col">ID</th>
                                    <th scope="col">Naam</th>
                                    <th scope="col">Opties</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($domains as $domain)
                                <tr>
                                    <th scope="row">{{$domain->id}}</th>
                                    <td>{{$domain->url}}</td>
                                    <td><a href="{{ route('domains.show', $domain->id) }}" class="btn btn-primary btn-font"><i class="fa fa-globe"></i> Bekijk domein details</a></td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                    <div>
                        <span>{{$page_number}}</span>
                        <button wire:click="decrement">-</button>
                        <button wire:click="increment">+</button>
                    </div>
                    <a href="{{ route('home') }}" class="btn btn-warning"><i class="fa fa-arrow-left"></i> Terug naar het dashboard</a>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

But it still doesn't work, maybe I didn't quite understand the second part of your explanation?

Activity icon

Started a new Conversation Livewire Not Updating A Value

Hey there guys,

I've recently made a component in Livewire for the first time. I didn't include it within a view, I load it in through a route instead. The basic thing is that I've made an increment and decrement method, They should update $page_number, but nothing seems to happen.

Here's the view that the component renders:

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-10">
            <div class="card">
                <div class="card-header">{{ __('Dashboard') }}</div>

                <div class="card-body">
                    <h2 class="text-center">Domeinen</h2>
                    <div class="table-responsive">
                        <table class="table">
                            <thead>
                                <tr>
                                    <th scope="col">ID</th>
                                    <th scope="col">Naam</th>
                                    <th scope="col">Opties</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($domains as $domain)
                                <tr>
                                    <th scope="row">{{$domain->id}}</th>
                                    <td>{{$domain->url}}</td>
                                    <td><a href="{{ route('domains.show', $domain->id) }}" class="btn btn-primary btn-font"><i class="fa fa-globe"></i> Bekijk domein details</a></td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                    <div>
                        <span>{{$page_number}}</span>
                        <button wire:click="decrement">-</button>
                        <button wire:click="increment">+</button>
                    </div>
                    <a href="{{ route('home') }}" class="btn btn-warning"><i class="fa fa-arrow-left"></i> Terug naar het dashboard</a>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

And here's the Component:

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use Illuminate\Support\Facades\Http;

class DomainList extends Component
{
    public $base_url = 'https://my.gridpane.com/oauth/api/v1/site?page=';
    public $page_number = 1;
    public $domains = [];
    public $first_page;
    public $last_page;
    public $prev = true;
    public $next = true;

    public function mount(){
        $response = Http::withOptions([ //use this method
            'verify'     => false, //This key and value in this method
        ])->withHeaders([
            'Content-Type'  => 'application/json',
            'Accept'        => 'application/json',
            'Authorization' => 'Bearer '.env('TOKEN'),
            'data-raw'      =>  [
                'summary' => true,
            ],
        ])->get($this->base_url.$this->page_number);
        
        $this->first_page = $response['links']['first'];
        $this->last_page = $response['links']['last'];
        $this->domains = collect($response['data'])->map(fn($site) => (object) $site);
    }

    public function increment(){
        $this->page_number++;
        // dd($this->page_number);
    }

    public function decrement(){
        $this->page_number--;
    }

    public function render()
    {
        return view('livewire.domain-list');
    }
}

I've read in the docs and looked it up and you need to apply an empty div around your code like it's a template. But I'd like to include the main styling of my website.

Feb
15
2 months ago
Activity icon

Replied to Changing Symlink On Webhosting

@jlrdw Tomorrow i will be able to work with a commandline in the webhosting. But for now this is the structure. I've already tried making a symlink, but that didn't seem to do a thing: https://prnt.sc/zmsk4z

Activity icon

Started a new Conversation Changing Symlink On Webhosting

Hey there, This is the first time i deployed a laravel project online with filezilla. I've put the entire project in a self made folder, and everything from the public folder is saved inside public_html. I also had to change 2 lines of code so that it can load the webapplication from my folder and that all works great. But the images and other stuff which i receive using asset(...) is not showing. I already tried a couple things but couldn't find a solution so far. Stuff like this: https://stackoverflow.com/questions/40870385/how-to-changed-default-path-public-name-in-laravel And creating a symlink change php file didn't work for me.

Activity icon

Started a new Conversation CURL Error 77: Error Setting Certificate Verify Locations

Hey there,

I implied laravel mail in my latest project. But i'm getting this error:

cURL error 77: error setting certificate verify locations: CAfile: curl.cainfo = D:\wamp64\bin\php\php7.4.9\extras\ssl\cacert.pem CApath: none (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://api.mailgun.net/v3//messages.mime

I've already followed these steps: https://stackoverflow.com/questions/30240840/laravel-5-socialite-curl-error-77-error-setting-certificate-verify-locations

But it's not working. Does anyone know the problem?

Feb
08
2 months ago
Activity icon

Replied to User Roles

Alright got it working! Appearently my role_id was 0 while the admin rank(first rank) in the table has a value of 1 because database tables start incrementing at 1 instead of 0 like an array

Activity icon

Replied to User Roles

Okay, so i had to change hasOne into belongsTo, otherwise they expect a user_id in the roles table. But now i get this error Trying to get property 'name' of non-object (View: D:\wamp64\www\webprepare_dashboard\resources\views\users\index.blade.php) which comes from the $user->role->name

Activity icon

Replied to User Roles

I did that yeah. But than i get this error SQLSTATE[42S22]: Column not found: 1054 Unknown column 'roles.user_id' in 'where clause' (SQL: select * from `roles` where `roles`.`user_id` in (1))

Activity icon

Started a new Conversation User Roles

Hi there, I'm trying to get simple user roles working. I just want every user to have a role, for example Visitor or Admin.

//User.php 
 public function roles()
    {
        return $this->hasOne(Role::class);
    }

//Role.php
public function users()
    {
        return $this->belongsToMany(User::class);
    }  

//User table migration
  $table->integer('role_id');
            $table->foreign('role_id')->references('id')->on('roles');

I'm just trying to accoplish to get that relationship working, so that i can do this in the html:

@foreach($users as $user)
	{{$user->role->name}}
@endforeach

Instead of doing:

@foreach($users as $user)
	{{$user->role_id}}
@endforeach
Activity icon

Replied to Shorten Validation Code

Alright, i'll check which one fits the best for me :)

Activity icon

Replied to Shorten Validation Code

Hmm, alright. I don't really understand your side note. Ofcourse I would like the ability to let users change their passwords. But they can do that with the Auth controllers etc? I just made this piece of code so that the admin can register new users, because i disabled registering.

Activity icon

Started a new Conversation Shorten Validation Code

I'm using this code to validate a user.

$validatedData = $request->validate([
            'name' => 'required',
            'email' => 'required|email',
            'password' => 'required|min:5',
        ]);

        $validatedData['password'] = Hash::make($validatedData['password']);

But since i'm using this code inside the store method and also the update method i want to know if i can make that piece of code reusable. I know about formrequests. But incase just want to make an extra function within my resource controller i could do something like

public function validated($request){
	$validatedData = $request->validate([
            'name' => 'required',
            'email' => 'required|email',
            'password' => 'required|min:5',
        ]);

        $validatedData['password'] = Hash::make($validatedData['password']);

		return $validatedData;
}

right?

EDIT:

I basically want to accomplish this with the above examples:

 public function store(Request $request)
    {
        $data = $this->validated($request);
        $user = User::create($data);

        return redirect('users')->with('success', 'Gebruiker is succesvol toegevoegd');
    }

Jan
11
3 months ago
Activity icon

Replied to Livewire Search Component.

@chaudigv I've modified my code with the addition of yours.

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use App\Models\Product;
use Illuminate\Database\Eloquent\ModelNotFoundException;

class ProductSearch extends Component
{
    public $product;
    public $search;
    public $error = '';

    public function searchProduct(){
        try {
            $this->product = Product::where('name', 'like', '%'.$this->search.'%')->first();
            $this->reset(['error']); // set $error to default i.e. ''
        } catch(ModelNotFoundException $e) {
            $this->error = 'Product not found.'; // your message when not product found.
        }
    }

    public function render()
    {
        // $this->product = Product::find($this->search);
        return view('livewire.product-search');
    }
}
<div>
    <form wire:submit.prevent="searchProduct">
        <input type="text" wire:model.defer="search">
        <button type="submit" >Search item</button>
    </form>
    @if(isset($product))
    <p>{{$product->name}}</p>
    @elseif(isset($error))
    <p>Product not found</p>
    @else
    <p>No data to be shown</p>
    @endif
</div>

So for example, the first time when you load the page, it says 'no data to be shown', after you search something and it found something it says the name of the product. And when you look for something that's not in the database you get the error. So it works correctly right, that the no data to be shown only appears at the beginning because the search method hasn't been execute yet?

Activity icon

Replied to Livewire Search Component.

Will ModelNotFoundException give me a 404 page or just the $error message you set?

Activity icon

Started a new Conversation Livewire Search Component.

Hey there guys! First time i've been actually using Livewire. I've made a simple search query component and it works. But i was just wondering, am I handling it the right way?

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use App\Models\Product;

class ProductSearch extends Component
{
    public $product;
    public $search;

    public function searchProduct(){
        $this->product = Product::find($this->search);
        // dd($this->product);
    }

    public function render()
    {
        // $this->product = Product::find($this->search);
        return view('livewire.product-search');
    }
}

And the rendered blade view:

<div>
    <form wire:submit.prevent="searchProduct">
        <input type="text" wire:model.defer="search">
        <button type="submit" wire:click="searchProduct">Search item</button>
    </form>
    @if(isset($product))
    <p>{{$product->name}}</p>
    @else
    <p>No data to be shown</p>
    @endif
</div>

I was just curious because now, when $product doesn't have a value, or the $product does not exist or whatsoever, i want it to display 'product not found' and i was wondering how i could do that check with eloquent.