Ranx99

Ranx99

Member Since 1 Year Ago

Experience Points 2,540
Experience Level 1

2,460 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 1
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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.

10 Jul
6 days ago

Ranx99 left a reply on Reset Auto Increment Id For The Tests?

Ok, so using DatabaseMigrations trait.. solves this for me

Ranx99 left a reply on Reset Auto Increment Id For The Tests?

@bobbybouwmann

As an example how I will test the order, It would be like this:


class test extends TestCase
{
    use RefreshDatabase;

    /** @test */
    public function posts_can_be_ordered_by_id_in_desc_direction()
    {
        factory(Post::class, 3)->create();

        $response = $this->get(route('posts.index', ['query' => '?order=id,desc']));
        $postsResultIdsArray = collect($response->decodeResponseJson()['posts'])->pluck('id')->toArray();

        $response->assertSuccessful();
        $this->assertEquals([3, 2, 1], $postsResultIdsArray);
    }

    /** @test */
    public function posts_can_be_ordered_by_id_in_asc_direction()
    {
        factory(Post::class, 3)->create();

        $response = $this->get(route('posts.index', ['query' => '?order=id,asc']));
        $postsResultIdsArray = collect($response->decodeResponseJson()['posts'])->pluck('id')->toArray();

        $response->assertSuccessful();
        $this->assertEquals([1, 2, 3], $postsResultIdsArray);
    }
}

If I run this tests one by one, it would pass, but when I run the whole test file.. it would fail..

What changes should I make to make it pass, when I run the whole test fie?

Ranx99 left a reply on Reset Auto Increment Id For The Tests?

@bobbybouwmann

Well I am trying to test the order of the posts..

When a user enters a URL like localhost/posts/?order=id,desc Or localhost/posts/?order=id,asc ..

So, I need to test if posts IDs are in the correct order ..

Ranx99 started a new conversation Reset Auto Increment Id For The Tests?

Lets say I have this test:

class test extends TestCase
{
    use RefreshDatabase;

    /** @test */
    public function test_ids_example()
    {
        $courses = factory(Post::class, 3)->create();
        $this->assertEquals([1, 2, 3], $courses->pluck('id')->toArray());
    }

    /** @test */
    public function test_ids_example_2()
    {
        $courses = factory(Post::class, 4)->create();
        $this->assertEquals([1, 2, 3, 4], $courses->pluck('id')->toArray());
    }
}

When I run the the test one by one, it passes.. but when I run the whole test file I get this error:

test::test_ids_example_2
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
-    0 => 1
-    1 => 2
-    2 => 3
-    3 => 4
+    0 => 4
+    1 => 5
+    2 => 6
+    3 => 7
 )

Because the tests doesn't reset the auto increment "id" even though I added "RefreshDatabase" trait. How to solve this? How can I rest the id for each test?

27 Jun
2 weeks ago

Ranx99 started a new conversation Is Browser Testing Needed?

Why would someone need to do browser testing?

Aren't "feature test" and "unit test" enough?

  • Is browser testing needed?
06 Jun
1 month ago

Ranx99 started a new conversation How To Use Php:artisan Outside App Folder?

I am structuring my app as modules, something like this

app/
bootstrap/
modules/
   -- Blog/
        --- Config/
        --- Console/
        --- Exceptions/
        --- Database/
                migrations/
                seeders/
                factories
        ---  Models/
        ---  Http/
                Controllers/
                Middleware/
        --- Providers/
        --- Resources/
        --- Routes/
                api.php
                web.php
        --- Tests/
   -- Backend/
   -- Frontend/
   -- Other modules etc..
config/
database/
public/
vendor/
resources/
other folders etc..

How can use artisan to make controllers, migrations, providers ... etc, inside a specific module?

For example lets say I am in this location: [email protected]:~/code/myblog/modules/Blog$

Is there a way to use artisan here? so I when I do php artisan make:controller TestController it will be placed in Blog/Http/Controllers

20 Apr
2 months ago

Ranx99 left a reply on How To Structure Folders ?

@pramanadiputra I like it, But I think this doesnt suite my use case? My case :

  • App\Admin ( admin dashboard )
  • App\User ( user dashboard )
  • App\Front ( front site)

Will use same database tables and models... for example: There is a category model which will be used for (index, show etc) to Front and User namespaces, but the same model also will be used in the Admin dashboard (create, edit, delete).

This where I am confused, since in your DDD everything is separated entirely.

Hope that makes sense..

19 Apr
2 months ago

Ranx99 left a reply on How To Structure Folders ?

Yeah both

  • App\Admin
  • App\User

Will have the same database table ( users table ), which has relationship with "roles" table

  • Admin role
  • User role
  • etc ..

But how to structure this folder, I was thinking of (DDD) style.. but I don't know how to apply it here.

Ranx99 started a new conversation How To Structure Folders ?

I am planning to create a site, which Its files and classes will grow big in the future...

I have :

  • Admin dashboard
  • User dashboard
  • Front site

Whats the best way to structure these folders? I was thinking of something like:

  • App\Admin
  • App\User
  • App\Front

That will help me when I want to add some new feature to Admin dashboard, I just go to App\Admin and add it. clean and maintainable..

Is it a good idea to do this?

  • Where each folder will have its own Http/ Providers/ .. etc. basically i will copy everything in app\ and paste it to 3 different folders names.
  • What if there is a provider in which it will be shared by all of these 3 folders?
  • Lets say there is a User model which will be used by both 3 folders? where to put it?

What are your experiences on this?

18 Apr
2 months ago

Ranx99 left a reply on What Does "concurrent Connections" Mean?

@cronix

So, as an example:

lets say I am using Pusher, and their free plan say you will have: 100 Max Connections 200k Messages / Day

Does it mean that I can handle only up to 100 users at the same time viewing the app ? And what do they mean by "200k Messages / Day"?

26 Mar
3 months ago

Ranx99 started a new conversation What Does "concurrent Connections" Mean?

I was reading about websockets and how to use it in laravel in here: https://murze.be/introducing-laravel-websockets-an-easy-to-use-websocket-server-implemented-in-php

I find it hard to understand what does "concurrent connections" means ( maybe because of my english )..

Can someone explain this to me in a simple way?

24 Mar
3 months ago

Ranx99 left a reply on Telescope Logs Shows An Empty Entries!!

It maybe worth mentioning that I have a fresh laravel install and laravel will create these log files automatically..

can these files be read by telescope?

23 Mar
3 months ago

Ranx99 started a new conversation Telescope Logs Shows An Empty Entries!!

When ever I try to open the logs section in telescope.. it shows me an empty entries, even though I have some logs files inside ( storage/logs ).

Why is that?

04 Mar
4 months ago

Ranx99 left a reply on Error While Setting Up "phpredis" Extension!

@MANELGAVALDA - That's right, I thought installing it via 'pecl' was enough..

I have add extension=redis.so to /etc/php/7.3/fpm/php.ini and now Its working..

thank you

Ranx99 left a reply on Error While Setting Up "phpredis" Extension!

@MANELGAVALDA - 'redis' => [

'client' => env('REDIS_CLIENT', 'phpredis'),

'default' => [
    'host' => env('REDIS_HOST', '127.0.0.1'),
    'password' => env('REDIS_PASSWORD', null),
    'port' => env('REDIS_PORT', 6379),
    'database' => env('REDIS_DB', 0),
],

'cache' => [
    'host' => env('REDIS_HOST', '127.0.0.1'),
    'password' => env('REDIS_PASSWORD', null),
    'port' => env('REDIS_PORT', 6379),
    'database' => env('REDIS_CACHE_DB', 1),
],

],

Ranx99 started a new conversation Error While Setting Up "phpredis" Extension!

Steps I did to install the extension:

  1. run pecl install redis (Installation from pecl).
  2. add extension=redis.so to /etc/php/7.3/cli/php.ini.
  3. change redis's client to "phpredis" instead of "predis" in config/database.php.

And I am getting this error: Call to undefined method Illuminate\Support\Facades\Redis::connect()

22 Feb
4 months ago

Ranx99 left a reply on Get Vimeo's Video Duration And Other Info

I think I need to use something like a cron job that will hits Vimeo API, any retrieve videos by a given ID ( video_id) .

did anyone worked with such a case with Vimeo before?

21 Feb
4 months ago

Ranx99 started a new conversation Get Vimeo's Video Duration And Other Info

In my website, I am allowing users to upload videos to Vimeo through their API to my account, then after uploading.. Vimeo will take sometime for trans-coding the uploaded video. And the uploaded video's info ( duration - size ..etc ) are not available until this video has finished trans-coding.

My problem: since they don't support webhooks ( Example: notify a given HTTP URL if trans-coding has finished for the uploaded video ).

I need another way to get these info when the video's has finished trans-coding, so I can store these values in my database table ( duration - size ..etc ).

How to solve this?

17 Feb
4 months ago

Ranx99 left a reply on Re-queue The Same Job Again Without Increasing Attempts..

After some search I found this: https://github.com/laravel/ideas/issues/735

but It seems their is no Larave built-in solution.

15 Feb
5 months ago

Ranx99 left a reply on Consume Same API For Both Web And Mobile Or Not?

I don't care much about which one is faster that the other that much. but in ( preloading data vs ajax request ) context..

which one to choose? what issues should I think about to decide?

14 Feb
5 months ago

Ranx99 left a reply on Consume Same API For Both Web And Mobile Or Not?

@CRONIX - @cronix thank you, so yeah its as you said :

preloading data vs ajax request..

Doesnt both are equally fast? since in preloading ( WebControllers ) I will communicate with database then call the view with the data and return it. ( VS ) In ( WebControllers ) only return a view then call API ( in vue ) to communicate with database for data?

If you had such a project ( not SPA ) which way you will go with?

Ranx99 left a reply on Consume Same API For Both Web And Mobile Or Not?

@AUDUNRU - Thanks, but since you said to use vue-router .. this means I would go for a SPA? right? .. which I don't want to do...

Ranx99 left a reply on Consume Same API For Both Web And Mobile Or Not?

@jlrdw I know the difference between the tow, I don't think you understand my question or I didn't make it clear?

13 Feb
5 months ago

Ranx99 started a new conversation Consume Same API For Both Web And Mobile Or Not?

Lets say I am building some large application ( multi-page app ) . And laravel will allow me to make an API and a website on the same application.

Since the website and the API will communicate with the same database, I was wondering if it is better to consume the same API for the website using Vue.js.

So this means I will make single entry point to the database for all the clients ( web , mobile..etc ).

And my plan is to make:

  • ApiControllers ( communicate with the database and return data )
  • WebControllers ( return blade views which have vue.js components to consume the API ) there is no communication with the database in these controllers.

What do you suggest?

Ranx99 left a reply on Re-queue The Same Job Again Without Increasing Attempts..

Thank you for the references. It seems the only way is to delete the job inside the condition and then dispatch it again. After some time playing with it I came up with something like this:

public function handle()
{
    try {
       // code
    } catch (InstgramApiRateLimitException $exception) {
        $this->reQueuejob($exception);
    } catch (Exception $exception) {
        $this->release(1800);
    }
}

private function reQueuejob(InstgramApiRateLimitException $exception)
{
    $this->delete();

    if ($this->job->isDeleted()) {
        dispatch(new self())->delay($exception->getRetryInSeconds());
    }
}

Is this a good way of doing it?

12 Feb
5 months ago

Ranx99 started a new conversation Re-queue The Same Job Again Without Increasing Attempts..

I am looking for a way to re-queue the same job back to the queue without increasing the number of jobs's attempts (tries) ..

class DeleteInstagramImage implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public  $tries  =  2;

    public function handle()
    {
        // do some code

        if ($condtion) { // ex: Instgram API rate limit has been reached its max limit..
          // re-queue 
        }
    }
}
19 Jan
5 months ago

Ranx99 left a reply on How To Keep Old Model's Data Until New Changes Are Approved ??

@eparcel_fi this seems a good solution for my problem, does anyone have used this before? also I came a cross:

https://github.com/owen-it/laravel-auditing

Can anyone have used these packages or something similar give me some feedback about if this is a good solution my probelm?

17 Jan
5 months ago

Ranx99 left a reply on How To Keep Old Model's Data Until New Changes Are Approved ??

@TRAY2 - Sorry, but I don't understand how does this solve the problem. can you explain more?

Ranx99 left a reply on How To Keep Old Model's Data Until New Changes Are Approved ??

so, I will create tow tables? something like: BookRevision and SectionRevision ?? this seems too complicated to do .. since a book will have many relations like ( sections - tags - category ) etc.. then I would create a table for each one ?

I think I could use morph relation to so I can have only one table for each one ( maybe call it 'revisionable' ) ??

there must be a package that does this.. I need to search more..

Ranx99 left a reply on How To Keep Old Model's Data Until New Changes Are Approved ??

Lets say the user deleted a section from this book.. or edited it..

Where does book's "sections" old data are stored?

Ranx99 started a new conversation How To Keep Old Model's Data Until New Changes Are Approved ??

Lets say I have this Scenario:

There is a model called Book, a book can have many chapters ( one-to-many relationship ) each chapter has many sections ( one-to-many relationship ).

class Book extends Model
{
    public function sections()
    {
        return $this->hasMany('App\Section');
    }
}
class Section extends Model
{
    public function chapters()
    {
        return $this->hasMany('App\Chapter');
    }
}

1 - user "A" has created a book ( title, desc, sections). 2 - user "A" asked for an approval from admin. then admin approve user "A" 's book. 3 - user "A" decided to delete a book's section, edit a section's chapter or maybe edit the book's title. 4 - then user "A" asked for a an approval from admin for these changes.

and then the admin can approve or disapprove these changes: 1 - if admin approve , apply the new changes. 2 - if admin disapprove , don't apply new changes. keep old data ( with its old relations data ( sections and chapters ).

How to accomplish something like this? is this possible?

18 Dec
6 months ago

Ranx99 left a reply on How To Access And Delete Polymorphic Relations?

@allw How to use cascade delete when there is no FK on content table? I think I need to handle it like this:

1 - game delete 2 - game delete listener 3 - delete game content and its children ( video or image ) when listener is triggered..

17 Dec
6 months ago

Ranx99 left a reply on How To Access And Delete Polymorphic Relations?

Thank you, another question lets say I deleted the media model and game model would be like this:

class Game extends Model
{
    public function mediable()
    {
        return $this->morphTo();
    }
}

Does that give me the same result as on my first post? what is the difference between the two?

Ranx99 started a new conversation How To Access And Delete Polymorphic Relations?

class Game extends Model
{
    public function media()
    {
        return $this->hasOne('App\Models\Media');
    }
}
class Media extends Model
{
    public function mediable()
    {
        return $this->morphTo();
    }
}
class Video extends Model
{
    public function media()
    {
        return $this->morphOne('App\Models\Media', 'mediable');
    }
}
class Image extends Model
{
    public function media()
    {
        return $this->morphOne('App\Models\Media', 'mediable');
    }
}
  • Each game will have one media type which are ( Video ) or ( Image ).

Questions:

  • When I delete a game I want to delete all of its relations in database.. how to do that?
  • How can I create a media ( video or image ) from Game model ? something like Game()->media()->createVideo()...
  • How can I access some a game's media info easily ?
15 Dec
7 months ago

Ranx99 started a new conversation Understanding Laravel Queue's Jobs When Failing..

I am using redis and laravel horizen for manging my queues.. this is only for testing queues, to understand how it works.

Now, when I dispatch this job, It will be processed ( 2 times ) and then it will fail if exception has been found.

class DeleteInstagramImage implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    
    public  $tries  =  2;
    
    public function handle()
    {
       // do some code, while throwing exception when error found.
    }

    public function failed()
    {
        $this->release(5);
    }
}

My questions:

  1. When I do $this->release(5) as I know It will add the job back the the queue. But why it doesn't start processing the job?

  2. How can I add a delay between the number of tries $tries = 2 of a single job? try #1 then after 5s try #2. Don't start processing try #2 immediately after the first one...

  3. How can I push a job to the bottom of queue when job is failed?

07 Dec
7 months ago

Ranx99 left a reply on Has Many Through Parent Scope

Was looking for the same thing.. any solution?

12 Oct
9 months ago

Ranx99 left a reply on Understanding Laravel Horizon's Processes And Queue Settings!

@D9705996

If I have a website and I want to send a verification email to a registered user's email ( via mailgun for example ). How can I tell what is the number of processes that is good for such a job?

11 Oct
9 months ago

Ranx99 started a new conversation Understanding Laravel Horizon's Processes And Queue Settings!

In Laravel Horizon's settings:

'local' => [
    'supervisor-1' => [
        'connection' => 'redis',
        'queue' => ['default'],
        'balance' => 'simple',
        'processes' => 3,
        'tries' => 3,
    ],
],
  • How can I determine the number of processes I should use in processes setting?
  • Is there a limit number of processes?
  • In the queue setting, as I understand this setting is for separating my queues ( Ex: uploadImageQueue, verfyEmailQueue, etc.. ) is this the right? is there a limit for the number of queues I can set?
10 Oct
9 months ago

Ranx99 started a new conversation How To Send An Email Verification For A Created User?

Lets say I am logged in as an Admin inside the admin panel: and I want to:

  1. Create a random user via admin panel.
  2. Send an email verification to that created user's email.

How to accomplish this?

11 Sep
10 months ago

Ranx99 left a reply on Admin Dashboard As SPA!

Thank you,

"It's not exactly an SPA"

I think Laravel Nova is a single-page app as I understand...

10 Sep
10 months ago

Ranx99 started a new conversation Admin Dashboard As SPA!

I am thinking of building the admin dashboard as single-page app with ( vue + vue router ). I haven't built SPA app yet, so this will be my first.

  • Is it good idea to build the admin dashboard as SPA? Did anyone tried it?
  • What is SPA's advantages Vs the classic way (MPA) in this case?

I want your inputs on the subject...

29 Aug
10 months ago

Ranx99 started a new conversation Laravel App Hosting

I am looking for a managed hosting for laravel app to setup LEMP fast..

I don't have time to watch over the server to deal with security and check for problems that it might have..

I was thinking going ( DigitalOcean + Forge ) but I will still have to monitor it..

25 Aug
10 months ago

Ranx99 left a reply on Where To Store External API Rate Limit Values?

Store API responses locally, especially if you expect a lot of traffic. In general, don’t call the API on every page load. Instead, call the API independently and load from cache on each page load.

Yes, this will be helpful if I use GET requests, but I am using POST ( upload a video file ) and Delete ( a video file ).

in Laravel docs it says:

If you are using the Memcached driver, items that are stored "forever" may be removed when the cache reaches its size limit. https://laravel.com/docs/5.6/cache

Doesn't this apply on redis also?

24 Aug
10 months ago

Ranx99 left a reply on Where To Store External API Rate Limit Values?

@Snapey

The reason why I want to store how many ( requests left ) is because I am using Vimeo's API ( which will block my app, if I exceeded the limit repeatedly - It will not just send back an error ) so I need to store these information somewhere...

Is it reliable to store these info in redis cache? and use cache::forever

Ranx99 started a new conversation Where To Store External API Rate Limit Values?

For example: Github, Twitter and Vimeo uses API rate limiting and will return ( in the response's headers ) something like this:

  • X-RateLimit-Limit
  • X-RateLimit-Remaining
  • X-RateLimit-Reset

For now, I am dealing with Vimeo's API and it will allow ( 500 request per 15 minutes ) and I was thinking of doing it like this:

  1. Prepare to send request to Vimeo's API.
  2. Check if ( X-RateLimit-Remaining ) value is > 0 ( in database ) or return error.
  3. Send request.
  4. Get the ( X-RateLimit-Remaining ) from this request response's header and replace it with the current one ( in database ).
  5. Reset ( X-RateLimit-Remaining ) value to 500 every 15 minutes.

Should I uses the database to store these values ? or using something like radis cache to store them ( I don't know if radis will cache these values forever or what happens to these values if the cache size reaches its limit ? or is there a better way?

02 Aug
11 months ago

Ranx99 left a reply on How To Use API Rate Limit For Any Authenticated Users?

I was thinking of something like this:

Route::group(['prefix' => 'auth:api', 'middleware' => 'throttle:500,15'], function () {
    Route::get('users/rate/limit', 'RateLimitControllr');
});

Does this effect all users or per-user ?

Ranx99 started a new conversation How To Use API Rate Limit For Any Authenticated Users?

For example: An API route that I want to allow 500 requests ( from any logged in user ) per 15 minutes

logged in user A requests the API => 499 remained logged in user B requests the API => 498 remained

*API rate-limit will be reset after 15 minutes

How to do something like this?

29 Jul
11 months ago

Ranx99 left a reply on Video Hosting And Streaming Solutions!

@jlrdw

I like Vimeo, but since I will allow users to upload their videos and Vimeo uses an API rate limit , doesn't that mean my app will get blocked if it exceeded that limit ?

27 Jul
11 months ago

Ranx99 started a new conversation Video Hosting And Streaming Solutions!

For an e-learning website project , what is the best service for video hosting and streaming? And since I want only allowed users who took some course to watch or download course's videos, I see these options:

  • S3 > Elastic Transcoder > Cloudfront ( Signed URLs)
  • Vimeo ( Private Link )
  • Wistia ( I don't know about it much )

I was wondering, which one is the cheapest service? is there a better one out there? I want your opinions and experiences in what is the best way to go..

21 Jul
11 months ago

Ranx99 left a reply on Vimeo For Business

@garethdaine

I have the same question, what did you end up with using?