pickab00

pickab00

Member Since 2 Years Ago

Experience Points
14,930
Total
Experience

70 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
31
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 3
14,930 XP
Oct
25
4 days ago
Activity icon

Started a new Conversation How To Save Only Related Array Data

I currently have an HTML like this:

<input type="text" name="name[]">
	<input type="text" name="address[]"><input type="text" name="loc[]">
	<input type="text" name="address[]"><input type="text" name="loc[]">
	<input type="text" name="address[]"><input type="text" name="loc[]">

<input type="text" name="name[]">
	<input type="text" name="address[]"><input type="text" name="loc[]">
	<input type="text" name="address[]"><input type="text" name="loc[]">
	<input type="text" name="address[]"><input type="text" name="loc[]">

And in my controller I am doing this:


foreach($request->name as $service) {

            $newService = new Service;

            $newService->name = $service;

            $newService->save();

                foreach ($request->address as $key => $addr) {

                    $newAddr = new Addr;

                    $newAddr->name = $addr;
                    $newAddr->loc = $request->loc[$key];

                    $newAddr->save();

                }
        }


This saves all the address (and loc) to one single "service". I am not sure how I can pass only the address and loc of the current "name". So in this case, for each "name" it stores all available address and loc. Instead I want to only store the address and loc for the current name.

Oct
09
2 weeks ago
Activity icon

Replied to Using Multiple Relationships On User

Will give polymorphic a try. Thanks!

Activity icon

Replied to Using Multiple Relationships On User

Yes I mentioned this in the question. My original question was that I know I can do this and I am currently doing this. I was wondering if there was an alternative to creating new fields in the table everytime I want to add a new module which the user relates to

Activity icon

Started a new Conversation Using Multiple Relationships On User

Hello,

The question title maybe deceiving because even I am not sure what I am looking for. The problem is that I have multiple "Modules" in my application. Suppose I have a restaurant module where I want to say that each user belongs to a restaurant. And therefore, the easiest way to do this would be to add a "restaurant_id" to the users table and write the relationships on the model. But what if in the future I added another module which each user belongs to that module as well. Then in that case, I will have to create another column in my users table for that module. How do I tackle this? How can I says that this user will belong to a restaurant and in the future add another module and the user belongs to that module as well? What would be the easiest and right approach for this?

Sep
26
1 month ago
Activity icon

Replied to Authentication In Lumen

I would suggest using something like passport.

Here is a great article on the installation

https://medium.com/@misteryomi/integrating-laravel-passport-in-your-lumen-project-with-example-1c2b8719c30

I would suggest using lumen as the backend and for frontend, use something like vue, react or something you are comfortable with. I would have also recommended laravel sanctum but its not supported for lumen. Good luck!

Activity icon

Awarded Best Reply on Laravel Sanctum API Login

I actually figured out what the issue was. In the Authenticate middleware, we have a method which redirects the user to login if attempt fails. So I just changed the redirect method or override it somewhere else

Activity icon

Replied to Laravel Sanctum API Login

I actually figured out what the issue was. In the Authenticate middleware, we have a method which redirects the user to login if attempt fails. So I just changed the redirect method or override it somewhere else

Activity icon

Started a new Conversation Laravel Sanctum API Login

So I have finally decided to use Laravel 8 with fortify/sanctum. But I am a bit confused as to why the default API route is redirecting me to the login page instead of showing me a message like "unauthenticated"

I have a custom login/register controller which simply registers or logs in the user and creates a new token using the $user->createToken('user-token'). But now when I try to go to this route:

Route::middleware('auth:sanctum')->get('index', [\App\Http\Controllers\TestController::class, 'index']);

in postman, it shows me the login page. How do I show the unauthenticated message? What am I doing wrong? By default, arent api routes supposed to authenticate with tokens and show unauthenticated if failed?

Sep
24
1 month ago
Activity icon

Replied to Where Clause In Polymorphic Relationship

I was actually looking for distinct() but your answer helped thanks

Activity icon

Started a new Conversation Where Clause In Polymorphic Relationship

I have 2 tables. 1 is the polymorphic table and the other is a simple posts table. Here:

posts:

 - id
 - title
 - detail

viewable:

 - uuid
 - viewable_type
 - viewable_id

and in my model:

//Post.php

public function views() {
      return $this->morphMany(Viewable::class, 'viewable');
}

//Viewable.php

public function viewable() {
        return $this->morphTo();
}

So now I want to get the total count of the items and I am doing this (which works):

$post = Post::find(1);
$post->views()->count(); //which works as expected

What I want to do is to check the UUID and check if the UUID exists in the table. Here is what I tried:

$post->whereHas('views', function($q) {
	$q->where('uuid', 'someuuid')
})->count();

This does not seem to work. And also, I want to take unique items only. So suppose the UUID is repeated in the table. I want to ignore the repeated and if the UUID exists, I want the count of that record as 1 (excluding the repeats)

Sep
23
1 month ago
Activity icon

Replied to How To Listen For Broadcasts

Hello,

I am using two applications. One application uses this package.

https://github.com/beyondcode/laravel-websockets

And from my main application, I am using websockets to receive data from anyone who is sending it (it can be on any channel) And from my second application, I am using the pusher drivers to broadcast an event to the main application. And now I am not sure how to receive the broadcasted message from the main application.

Activity icon

Awarded Best Reply on Adding DisplayUsing Method To Different Methods

For anyone asking, Nova has methods where you can show a specific field on a specific page (index, update etc). So just use the onlyOnIndex() to show the above trimmed code and onlyOnDetail() to show it on the detail page without the displayUsing method

Activity icon

Replied to Adding DisplayUsing Method To Different Methods

For anyone asking, Nova has methods where you can show a specific field on a specific page (index, update etc). So just use the onlyOnIndex() to show the above trimmed code and onlyOnDetail() to show it on the detail page without the displayUsing method

Activity icon

Started a new Conversation How To Listen For Broadcasts

I have seen many posts about broadcasting using pusher. And the listeners are always using Echo (js) to listen for broadcasts on a channel. But I was wondering if there was a way to listen for broadcasts using php/laravel. I wanted to make a command which will listen for broadcasts on a channel. I could not find anything relative to this

Sep
21
1 month ago
Activity icon

Started a new Conversation Adding DisplayUsing Method To Different Methods

So I have added fields to nova with the displayUsing() method which I am using to trim down the string to shorten it. I want to shorten it only on the index/table view and not on the show. Currently what I have is this:

Text::make('data')
                ->displayUsing(function ($text) {
                    if (strlen($text) > 30) {
                        return substr($text, 0, 30) . '...';
                    }
                    return $text;
                }),

Which is correct and I can successfully trim the text down to 30 characters but this applies to all view including show. How can I not trim the show method and just the index?

Sep
16
1 month ago
Activity icon

Replied to Trying To Get Property Id Of A Non-object

Hello. I have already tried decoding but that didn’t work. And is there any way I could achieve this without casting from model?

Activity icon

Started a new Conversation Trying To Get Property Id Of A Non-object

I am getting Trying to get property id of a non-object error while trying to read from a json object. Here is my output as it is.

{"name":"name test","email":"[email protected]","updated_at":"2020-09-16T07:30:30.000000Z","created_at":"2020-09-16T07:30:30.000000Z","id":134}

And from my code this is what outputs the above result:

$message->body and I am trying to do this $message->body->id

A little background. The above mentioned object is stored as it is inside a table column. I am fetching it and trying to read it. I am not sure why I can't. What am I missing? I should be able to access it as it is a json object correct?

Sep
14
1 month ago
Activity icon

Replied to How Can I Keep A Command Live

I can’t have 2 best answers selected but thank you!

Activity icon

Replied to How Can I Keep A Command Live

What I meant was, I know I can run it forever and I want the console to be running and showing me any information which it throws. Suppose the message I pass in, as soon as I pass it in and receive it on the other end, I want the console to log it so I can see it through the console first. That is what I meant.

Activity icon

Replied to How Can I Keep A Command Live

It’s actually not a model update. That was a very badic example. Basically, I’m using RabbitMQ and this package: https://github.com/bschmitt/laravel-amqp to send data to queue. And I want to get these data from the queue using this:

Amqp::consume('queue-name', function ($message, $resolver) {

var_dump($message->body);

$resolver->acknowledge($message);

$resolver->stopWhenProcessed();

});

I know the package has a way to get messages forever. But I want to run the above code and keep it always running

Activity icon

Started a new Conversation How Can I Keep A Command Live

How can I keep a custom command live? I just made a command which just prints a random variable if something changed on the user model.

Currently I’m doing:

‘’’ while (true) { if(User::where(active, null)->exists()){ $user = User::where(active, null)->get(); $user->active = 1; $user->update(); } return “updated”; } ‘’’ So in this case, how can I always keep on running this app continuously and see returns in console? Is using while true a good idea? Whats the best way to do it?

Edit: sorry I’m on mobile and the code block is not working

Sep
12
1 month ago
Activity icon

Awarded Best Reply on Guzzle/Http POST Request Not Working As Expected

Well... It turns out, I forgot to clear cache. So in case someone runs to something similar to this, just do

php artisan config:clear
php artisan config:cache
php artisan cache:clear
php artisan optimize
Activity icon

Replied to Guzzle/Http POST Request Not Working As Expected

Well... It turns out, I forgot to clear cache. So in case someone runs to something similar to this, just do

php artisan config:clear
php artisan config:cache
php artisan cache:clear
php artisan optimize
Activity icon

Replied to Login Through Facebook

Laracast really needs to do quality control. No offense but that question does't give us any clue of what the error is. It does not have any details nor codes. Show us what you already did and maybe use pastebin to paste the log file details or something. Just giving the partial exception is not going to resolve the answer. We are as clueless as you are right now

Activity icon

Started a new Conversation Guzzle/Http POST Request Not Working As Expected

Hi,

I am definitely missing something here and I can't seem to figure out what the exact issue is. Here is the problem:

I have a lumen project which is expecting an API call to a route (post method). And in the controller, all I am doing is inserting the data which is sent over to the API. Now I have a separate Laravel project which is making this call. I am trying to make a package for this. So far, I have made the service providers and all the necessary classes. The main class is responsible for making the API call to the Lumen project. However, when I make the call using Http (or guzzle), it says Table 'eventstest.applications' doesn't exist. Now, that's fine and all, except, I am making the call to my Lumen project from my Laravel project and Laravel project is throwing this error. And eventstest is the name/db of my Laravel project. However, the API from Lumen is throwing that error and the db of that project is called events. Its supposed to be looking for a table named applications inside the events database. But whenever I make the guzzle/http call from Laravel to the Lumen (events) project, I am getting the error stating that Table 'eventstest.applications' doesn't exist. My Laravel projects database is eventstest.

Here is the API end point from Lumen (shortened):

public function logEvent(Request $request) {
        
        //check if the application id matches the given app_id
        if(Application::where('application_id', $request->header('Authorization'))->doesntExist()) abort(403, 'App key not found for the given application');
        
        return 'Logged';

    }

Here is the API call made from Laravel Project (Shortened):

public function PostEvent($url) {
        
        $response = Http::withHeaders([
            'Authorization' => 123
        ])->post('http://something.io/api/events', [
            'url' => $url,
        ]);

        $statusCode = $response->status();
        
        return $response;
    }

And finally, from my Laravel Project, here is the web.php route and controller:

Route::get('/', [TestController::class, 'index']);
public function index() {

        $events = new Events();

        return $events->PostEvent('some random url');

    }

So the Events() class is coming from the package I am making and the code for that is above. I am simply importing this class in to my controller and making a call from the default route / to the API using http/guzzle. But the line where it says if(Application::where('application_id', $request->header('Authorization'))->doesntExist()) abort(403, 'App key not found for the given application') says that the eventstest.applications table not found. The Lumen projects db is events and laravels db is eventstest. Why is it assuming that the db of that Lumen project (API) is eventstest?

Sep
10
1 month ago
Activity icon

Replied to Need Help With Brainstorming An Idea For A Centralized Events Catcher

Thank you for this! So what I had in mind was to create the API and an extra websocket (so any application Which supports this can use it as well to use real-time pushes in a queue). So we can utilize laravels broadcasting and queuing as well. Thanks a bunch for the opinion!

Sep
09
1 month ago
Activity icon

Started a new Conversation Need Help With Brainstorming An Idea For A Centralized Events Catcher

Hello everyone

I needed an idea to create a centralized application which will catch all the events data in to itself. Let me explain:

Currently I have a lot of applications running on docker which depends on each other. We could says they are all decoupled micro services. We have a separate auth manager using laravel, a lot of other applications and so on. What I want to do is, whatever happens in each of the system, I want to catch the events of that and store them in one place. Suppose a part of the application set is a normal blog. Now the users will add, update and delete posts. I want to record all that information (crud operation) on another application (which specializes in catching and storing these “events”). I’m calling it events here for now. What I had in mind was to use lumen. Would it be a good idea to create a small php package to make all API calls to lumen for storing each event detail? Is it a good idea to make API calls to store this data? There will be about (this is an approximation) 50,000-100,000 requests (post, get, put, delete) made every day. So I wanted some recommendations on how to do this. My first idea is to use lumen with API calls to it. The action (put, post, delete etc) will pass the required data. The lumen application will also reside in docker along with the rest of many applications. Everything is currently running off of laravel and so I was thinking of making a package as the middle man to handle the API side of things. And any failed attempts will be logged on to a local table in the database. What are you guys thoughts? Should I go for API or do you guys have a better idea on how to do this?

If you reached here, I salute you!

Jun
10
4 months ago
Activity icon

Awarded Best Reply on Having Trouble With User Verification

Actually got it to work now. Just added to check if the current route is not verify form route. If it isn't, then it will not redirect

Activity icon

Replied to Having Trouble With User Verification

Actually got it to work now. Just added to check if the current route is not verify form route. If it isn't, then it will not redirect

Activity icon

Started a new Conversation Having Trouble With User Verification

So I have a field in my user table "verified" and I want to check if this is null or not. If it is null, it should redirect back to a route.

Now I wrote a middleware which is very basic and looks like this:


if(Auth::check()) {

            $auth = Auth::user();

            if($auth->verified == null) {
                return redirect()->route('show.type.coming.soon');
            }
        }

return $next($request);

Now the error is ERR_TOO_MANY_REDIRECTSERR_TOO_MANY_REDIRECTS now I know why this is because the above if always returns true. Now how can I say that I am already at that route and to not redirect again? Or is there a better approach?