grunburg

grunburg

Member Since 6 Months Ago

Experience Points
2,000
Total
Experience

3,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
10
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

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

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

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

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

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

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

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

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

Level 1
2,000 XP
Sep
02
1 month ago
Activity icon

Replied to SQLSTATE: Not Null Violation: 7

@automica Thanks, I totally forgot about $fillable.

Activity icon

Started a new Conversation SQLSTATE: Not Null Violation: 7

I'm making an API authentication system. Currently testing register action, I ran into this problem, that I can't solve:

SQLSTATE[23502]: Not null violation: 7 ERROR:  null value in column \"handle\" violates not-null constraint\nDETAIL:  Failing row contains (12, Test, null, [email protected], null, password, null, 2020-09-02 10:59:53, 2020-09-02 10:59:53). (SQL: insert into \"users\" (\"email\", \"name\", \"password\", \"updated_at\", \"created_at\") values ([email protected], Test, password, 2020-09-02 10:59:53, 2020-09-02 10:59:53) returning \"id\")

Im posting data from Postman with all the keys and values, including handle (@username).

Authcontroller.php

class AuthController extends Controller
{
  public function register(Request $request)
  {
    $data = $request->validate([
      'email' => ['email', 'unique:users', 'required'],
      'name' => ['string', 'max:225', 'required'],
      'handle' => ['string', 'alpha_num', 'unique:users', 'max:16', 'required'],
      'password' => ['confirmed', 'required']
    ]);

    $user = User::create($data);

    $token = $user->createToken('Auth')->accessToken;

    return response(['user' => $user, 'token' => $token], 201);
  }
}

migration file:

public function up()
{
  Schema::create('users', function (Blueprint $table) {
    $table->id();
    $table->string('name');
    $table->string('handle')->unique();
    $table->string('email')->unique();
    $table->timestamp('email_verified_at')->nullable();
    $table->string('password');
    $table->rememberToken();
    $table->timestamps();
  });
}

Is there some kind of typo I don't see or just something wrong with my code?

Aug
31
1 month ago
Activity icon

Replied to Resource Collection By User Id

Thanks @geordiejackson, works like I wanted to. Just small error there, should be $user->posts()->paginate(10) :)

Activity icon

Replied to Resource Collection By User Id

Thanks, it works, but I'm still searching how can I do it with resource collection. I'm creating a API with Laravel.

Activity icon

Started a new Conversation Resource Collection By User Id

I'm trying to get every post (paginated) by specific user defined in url e.g /users/1/posts/

So far I have added PostCollection to index action, but if I hit /users/{user}/posts/ endpoint, I get response with posts, all from diferent users. What am I doing wrong?

PostController.php

public function index(User $user): PostCollection
{
    return new PostCollection(Post::paginate(10));
}

PostCollection file is default, what should I add to make with work?

Jun
26
4 months ago
Activity icon

Started a new Conversation Trouble Connecting To PostgreSQL Database.

When command php artisan migrate is ran, I get this error:

Illuminate\Database\QueryException 

could not find driver (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations and table_type = 'BASE TABLE')

at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
  667|  // If an exception occurs when attempting to run a query, we'll format the error
  668|  // message to include the bindings with SQL, which will make this exception a
  669|  // lot more helpful to the developer instead of just the database's errors.
  670|  catch (Exception $e) {
> 671|      throw new QueryException(
  672|          $query, $this->prepareBindings($bindings), $e
  673|      );
  674|  }
  675| 

 +34 vendor frames 
  35  artisan:37
  Illuminate\Foundation\Console\Kernel::handle()

This is my .env file:

DB_CONNECTION=pgsql
DB_HOST=host.docker.internal
DB_PORT=5432
DB_DATABASE=name
DB_USERNAME=user
DB_PASSWORD=secret

And checking phpinfo() within Laravel App, I can confirm that pgsql and pdo_pgsql extensions are installed.

Also by doing php -m inside docker CLI, both extensions are there.

Been on this error for some quite time and still can't figure out what's wrong. I hope someone can help me with this mess... :(

Edit: forgot to add my Dockerfile

FROM php:7.4-fpm

RUN apt-get update && apt-get install -y libpq-dev

RUN docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql

RUN docker-php-ext-install pdo pdo_pgsql pgsql bcmath
May
07
5 months ago
Activity icon

Replied to Alpine.js Interfieres With Vue.js

Thanks for the answers.

Activity icon

Started a new Conversation Alpine.js Interfieres With Vue.js

I really like Alpine.js implementation of @click dropdown, tabs etc. The only problem is – Alpine interfieres with Vue. For example if I make simple dropdown:

<div x-data="{ open: false }">
  <button @click="open = true">Open Dropdown</button>

  <ul x-show="open" @click.away="open = false">
    Dropdown Body
  </ul>
</div>

It doesn't work and I get this following error:

[Vue warn]: Property or method "open" is not defined on the instance but referenced during render.

If I remove app.js which contains Vue, I get no errors and Alpine is now working.

Is this fixable?

May
06
5 months ago
Activity icon

Started a new Conversation SQL LIKE Operator Returns Everything From Table Even If String Is Empty.

I'm making a search system and I'm encountering an bug where if $search string is empty, DB returns every user.

If I enter first letter of username, everything works normal. Shouldn't it be if string is empty, no user is returned.

$search = '';

$users = DB::table('users')
  ->where('username', 'like', "{$search}%")
  ->get();

return $users;

Is this a bug or it works like intended? How can I fix this, so empty string returns nothing.

Activity icon

Awarded Best Reply on Livewire Search Isn't Working

Sorry, just saw my mistake... I accidentally wrote @livewrieScripts instead of @livewireScripts.

Activity icon

Replied to Livewire Search Isn't Working

Sorry, just saw my mistake... I accidentally wrote @livewrieScripts instead of @livewireScripts.

Activity icon

Started a new Conversation Livewire Search Isn't Working

I'm trying to setup search-bar to search for users. I'm currently stuck somewhere with returning input data.

namespace App\Http\Livewire;

use App\User;
use Livewire\Component;

class SearchUsers extends Component
{
  public $search = '';

  public function render()
  {
    return view('livewire.search-users', [
      'users' => User::where('username', $this->search)->get(),
    ]);
  }
}

The input doesn't return anything. But If I change this line $this->search to 'grunburg it returns the user where foreach grabs my username, so technically this component is working. My guess there is something wrong with input that I can not pinpoint.

<div>
  <input wire:model="search" type="text" placeholder="Search users..." />

  <ul>
    @foreach($users as $user)
      <li>{{ $user->username }}</li>
    @endforeach
  </ul>
</div>

What could be wrong on why I'm not getting any data back?

Activity icon

Replied to Access All Users In Layout.blade

Oh nice, that's what I was looking for. Thanks @michaloravec

Activity icon

Started a new Conversation Access All Users In Layout.blade

I'm trying to display all users inside navigation bar. How can I loop through all user usernames?

Everything I got so far...

@foreach($users as $user)
  <li>{{ $user->username }}</li>
@endforeach

I know that I have to access User model, but how can I do that inside blade?

May
05
5 months ago
Activity icon

Started a new Conversation Real-time Notifications Are Not Working

I'm trying to create a real-time notification system that notifies post creator if someone has posted a comment on his post. I have set everything up and I'm receiving events on Pusher console, but on website nothing is listening to posted comment.

New notification (notification count) only shows up after refresh.

Here is notifications dropdown with laravel-echo

<!-- Notifications.vue -->
<template>
  <div>
    <button>
      Notifications
      <span>{{ notifications.length }}</span>
    </button>
    <div>
      <p>{{ notification.data.username }} has commented on your post.</p>
    </div>
  </div>
</template>

<script>
export default {
  props: ['unreads', 'userid'],
    data: function () {
      return {
        notifications: this.unreads
      }
    },
    mounted() {
      Echo.private('App.User.' + this.userid)
        .notification((notification) => {
          console.log(notification);
          let newNotification = { data: { image: notification.image, username: notification.username } }
          this.notifications.push(newNotification);
        });
    },
}
</script>

I'm also using Vue to post comments

<!-- CommentForm.vue -->
<template>
  <form method="post" @submit.prevent="addComment()">
    <input placeholder="Add a comment..." type="text" name="comment" id="comment" v-model="comment">
        <button>Post</button>
  </form>
</template>

<script>
  export default {
    props: ['id'],
    data: function () {
      return {
        comment: '',
      }
    },
    methods: {
      addComment() {
        axios.post('/p/' + this.id + '/comment', { comment: this.comment })
          .then(response => {
            Event.$emit('commentCreated', response.data.comment)
            this.comment = ''
          })
      },
    },
  }
</script>

I have absolutely no idea what could be wrong.

Apr
26
6 months ago
Activity icon

Replied to Hide Specific Route Or Data

@wingly Thanks, will look into API Resources. To get user's username on the comment, I have to load in user $post->comments->load('user')

Activity icon

Started a new Conversation Hide Specific Route Or Data

I have this route /p/{post}/comments that returns json array with comments and user that has commented. This exposes user data, especially, user's email.

How can I hide this route so others can not access it or should do something different in this case?

Activity icon

Started a new Conversation Carbon ShortAbsoluteDiffForHumans() For Javascript/Vue

Is there some kind of Javascript package that displays time format like Carbon? I really like Carbon's shortAbsoluteDiffForHumans() function that displays long format date, for example, 2020-04-23 18:32:26 to short date format 3d

Activity icon

Replied to Getting An Vue Error While Posting

Ah, what a relief. Everything works just fine now. Thanks a lot @wingly!

Activity icon

Replied to Getting An Vue Error While Posting

This is what I have right now and the same error is still there.

export default {
  props: ['id'],
  data: function () {
    return {
      comment: '',
    }
  },

  methods: {
    addComment() {
      axios.post('/p/' + this.id + '/comment', { comment: this.comment })
        .then(response => {
        Event.$emit('commentCreated', { comment: response.data.comment })
        this.comment = ''
      })
    }
  }
}
Activity icon

Replied to Getting An Vue Error While Posting

@wingly Getting the same

Error in render: "TypeError: Cannot read property 'username' of undefined"

And as for console log: console.log

Activity icon

Replied to Getting An Vue Error While Posting

This is my CommentsController:

class CommentsController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }

    public function index(Post $post)
    {
        $post->comments->load('user', 'user.profile');
        return $post->comments;
    }

    public function store(Post $post, Request $request)
    {
        $comment = $request->user()->comments()->create([
            'comment' => $request->input('comment'),
            'post_id' => $post->id
        ]);
    
        $comment->load('user', 'user.profile');

        return response()->json(['comment' => $comment]);
    }
}

I edited the line you just sent me, but now nothing will post and I'm getting this error:

Error in v-on handler: "ReferenceError: response is not defined"
Activity icon

Replied to Getting An Vue Error While Posting

Still getting the same Vue error.

Activity icon

Replied to Getting An Vue Error While Posting

@wingly The problem is somewhere while posting the comment because after a refresh the comment is there with the username.

This is what I get p/2/comments (I have created relation with user an user profile) :

[{"id":1,"post_id":2,"user_id":1,"comment":"Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.","created_at":"2020-04-23T18:32:26.000000Z","updated_at":"2020-04-23T18:32:26.000000Z","user":{"id":1,"username":"grunburg","name":"Ri\u010dards","email":"[email protected]","email_verified_at":null,"created_at":"2020-04-23T14:15:11.000000Z","updated_at":"2020-04-23T14:15:11.000000Z","profile":{"id":1,"user_id":1,"title":"Ri\u010dards","description":"This is an Example Bio.","url":null,"image":"profile\/7wsdU2Rt3thJwnCAxuXKtwalUMYRX4VBPspUV5I8.jpeg","created_at":"2020-04-23T14:15:11.000000Z","updated_at":"2020-04-26T13:40:34.000000Z"}}}]
Activity icon

Replied to Getting An Vue Error While Posting

@bobbybouwmann The URL returns comment with user and user profile.

Edit: oh store method, let me try this, sorry.

Activity icon

Started a new Conversation Getting An Vue Error While Posting

I'm getting an error while posting a comment

Error in render: "TypeError: Cannot read property 'username' of undefined"
&
TypeError: Cannot read property 'username' of undefined

This only happens when I add this line comment.user.username inside Comments.vue to get username of the user who posted the comment. If I refresh the page, the comment is there.

This is what I'm using to post a comment

<!-- CommentForm.vue -->
<template>
  <form method="post" @submit.prevent="addComment()">
    <input type="text" name="comment" id="comment" v-model="comment">
    <button class="text-blue-600 font-medium focus:text-blue-700 focus:outline-none">Post</button>
  </form>
</template>

<script>
  export default {
    props: ['id'],
    data: function () {
      return {
        comment: '',
      }
    },

    methods: {
      addComment() {
        axios.post('/p/' + this.id + '/comment', { comment: this.comment })
            Event.$emit('commentCreated', { comment: this.comment })
            this.comment = ''
      }
    }
  }
</script>

This is what I'm using to fetch comments and display them:

<!-- Comments.vue -->
<template>
  <div v-for="comment in comments">
    <!-- Error happens here. If I remove {{comment.user.username}} everything works without a problem -->
    <p><a href="#">{{comment.user.username}}</a> {{comment.comment}}</p>
  </div>
</template>

<script>
  export default {
    props: ['id'],
    data: function () {
      return {
        comments: [],
      }
    },

    created() {
      axios.get('/p/' + this.id + '/comments')
        .then(response => this.comments = response.data)

      Event.$on('commentCreated', (comment) => {
        this.comments.push(comment)
      })
    },
  }
</script>

What could be the problem, how can I fix this?

Apr
25
6 months ago
Activity icon

Replied to Get Comments By Post Id With User Data

@michaloravec Thanks! Everything works!

Activity icon

Started a new Conversation Get Comments By Post Id With User Data

I'm fetching comments by post ID and displaying them using Vue.

By using this in controller, I get the comments that correspond to post ID:

return $post->comments;

But to get usernames of users who posted comments I have to include user data together with comments:

return Comment::with('user')->get();

But this returns all comments without taking post id into account.

The question is, how can I merge these two lines of code, so I get comments by post id and with user data?