xdimension

xdimension

Member Since 4 Years Ago

Experience Points 19,655
Experience Level 4

345 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 186
Lessons
Completed
Best Reply Awards 9
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.

18 Jun
3 years ago

xdimension left a reply on How Should I Change The Definition Of The Variable?

@maftyycs Change this code:

@foreach ($requests as $user)
    @include('user/partials/userblock')
@endforeach 

to:

@foreach ($requests as $request)
    @include('user/partials/userblock', ['user' => $request])
@endforeach

so your $user is not overwritten, do the same for another foreach block.

01 Jun
3 years ago

xdimension left a reply on Divide Collection Into Parts On Laravel

@jay_gorio Instead of splice you might be able to use chunk(n) (see: https://laravel.com/docs/5.2/collections#method-chunk), but I don't think this is what you want as you can't specifically set which courses are in each semester. If that's the case, you need a column/field to indicate which courses are in the first semester and second, then separate them in the query (could be using group by like said above) before passing it to the view.

27 May
3 years ago

xdimension left a reply on Best Way To Seed Core, Non-test Data?

I haven't tried this, but this package might help https://github.com/slampenny/SmartSeeder

14 May
3 years ago

xdimension left a reply on Problem Drop-down Json In Form Edit.blade Province Anda City

@nero You need to add $id in the function parameter:

Route::get('event/{id}/provinces/{code}/cities.json', function($id, $code)
{
    return \App\City::where('province_id',$code)->get();
});
04 May
3 years ago

xdimension left a reply on Add Route() Parameter With VueJs

I've just tried it in artisan tinker and it does work, except the route function encode the {} characters :/ So, another trick might be needed, what's in my mind now is simply using str_replace:

str_replace('page.id', '{{ page.id }}', route('edit_page_path', ['page.id']))

not the best code in the world, but hey it works! :D and we can create a helper function to make it pretty,

xdimension left a reply on Add Route() Parameter With VueJs

@zachleigh If I understand OP's question correctly, he wanted to get the page.id on the client side (or by Vue), by passing as string hopefully the result that was rendered by Blade as

'/my/test/route/{{ page.id }}'

and Vue can take care of {{ page.id }}

xdimension left a reply on Add Route() Parameter With VueJs

@Mike I'm not sure, but maybe you can do it like this:

<a href="{{ route('edit_page_path', ['@{{ page.id }}']) }}">
      @{{ page.title }}
  </a>

so basically you pass it as string '@{{ page.id }}'

xdimension left a reply on VueJS - Update Dom After Nested Array Updates

@philbenoit Yeah, my idea was adding flightTimes to airports data so Vue will render to DOM when it's changed like @tjames explained in point 1.

xdimension left a reply on Laravel 5.2 IoC Doesn't Work In Custom Classes

@cornelyu85 Have you resolved your custom class using IoC ?

$obj = app(App\Services\CustomClass::class);

xdimension left a reply on Vue.js 2.0

Nice, but it's still in pre-alpha version, right?

xdimension left a reply on VueJS - Update Dom After Nested Array Updates

@philbenoit How about adding the flightTimes in the object before pushing to array?

With dates: https://jsfiddle.net/sy6bat5z/2/ Without dates: https://jsfiddle.net/sy6bat5z/3/

xdimension left a reply on Repository Pattern Still Worth?

@ohffs No, I can't, as Model is not Facade. Even if I can, I don't think to write $model->shouldReceive('eloquent_methods') for every methods being used in the query. If I use repository, I can write $repo->shouldReceive('repo_method'), so when the query changes later, I don't need to update the test. I'm actually curious to OP's question as well, if there is any better solution for Repository Pattern.

xdimension left a reply on Repository Pattern Still Worth?

<sorry, moved my question from another thread>

If we don't use Repository, how to test the Service class? Supposed I have this Service class:

class CustomerBills
{
    public function listUnbilledUsers($period)
    {
          return Bills::where('billed', 0)->where('period', $period)->get();
    }
}

I don't think we can easily mock the Bills model there. I agree that somehow Repository isn't suitable for Active Record like Eloquent, but so far I couldn't find easier way to test a Service class without injecting the repository.

xdimension left a reply on Reasons I Abandoned Repository Pattern In Laravel

Sorry to bump up an old thread, but I have a question regarding this topic.

If we don't use Repository, how to test the Service class? Supposed I have this Service class:

class CustomerBills
{
    public function listUnbilledUsers($period)
    {
          return Bills::where('billed', 0)->where('period', $period)->get();
    }
}

I don't think we can easily mock the Bills model there. I agree that somehow Repository isn't suitable for Active Record like Eloquent, but so far I couldn't find easier way to test a Service class without injecting the repository.

08 Apr
3 years ago

xdimension left a reply on Best Way To Schedule Task As Per User's Timezone

@alexmansour Ah okay, you're correct, it schedules tasks only at a time based on the timezone.

I usually save user's timezone in the user profile (they choose it), so maybe in the task itself we can check whether it's at user's time, and the schedule should run hourly or half an hour depends on the time period.

xdimension left a reply on Prevent Validation When Another Field Isn't Present

@quarkmarino You can add validator() method in your Form Request like this:

public function validator($factory)
{
        $v = $factory->make(
              $this->all(), $this->container->call([$this, 'rules']), $this->messages(), $this->attributes()
        );

        $v->sometimes('contribution_plan.amount', 'required|numeric', function($input) {
              return $input->contributions;
         });

         return $v;
}

This method will be called in https://github.com/laravel/framework/blob/5.2/src/Illuminate/Foundation/Http/FormRequest.php#L78

05 Apr
3 years ago

xdimension left a reply on Vue.JS Vue-Tables Laravel Relationship

@Melcus $http.get just retrieves the data from the JSON. As you're using accessor then you can check what it returns to your JSON and changes how you format the date.

04 Apr
3 years ago

xdimension left a reply on Vue.JS Vue-Tables Laravel Relationship

Sorry, I couldn't get back to you earlier. Glad to see it's resolved.

Maybe just an additional information: If you're using <v-client-table ...>, then yes, you need to retrieve the data from the server using vue-resource (this.$http.get(...)) as you did. But from the doc, I see another option to do it, you can use <v-server-table url="/api/footage" ...>, it requires you to return a JSON from the server-side in this format:

{ 
      data: [
           // row objects of your data and each row should be flattened (not nested)
           {id: 1, name: "John", ... },
           {id: 2, name: "Doe", ... },
           ...
      ],

     count: 5
}

I think internally it would do the same as what you did using <v-client-table> and vue-resource.

xdimension left a reply on Vue.JS Vue-Tables Laravel Relationship

Maybe you need to return the data from server side in a flat format instead of nested. Then (from the doc) you can use `<v-server-table url="/api/footage" :options="options"></v-server-table>'

xdimension left a reply on Prevent Validation When Another Field Isn't Present

@quarkmarino I think you can use sometimes rule, you can also define when sometimes rule being triggered to satisfy your case like this:

$v->sometimes('contribution_plan.amount', 'required|numeric', function($input) {
    return $input->contributions;
});

See here: https://laravel.com/docs/5.1/validation#conditionally-adding-rules

25 Mar
3 years ago

xdimension started a new conversation CodeCeption CanSeeLink Always Passes

I just realize that my acceptance test that is using canSeeLink (from WebDriver module) always passes whatever the url is. :doh:

Here is my test:

public function test_a_page(AcceptanceTester $I)
{
    $I->amOnPage(...);
   
    $I->canSeeLink('Edit', route('edit', ['id' => $id]));
}

The first issue, route() returns an url like http://localhost/edit/1. I'm wondering why it doesn't get the APP_URL from .env.testing:

APP_URL = http://app.test

which then I set that in config/app.php as:

'url' => env(APP_URL, 'http://localhost')

I also set the url in acceptance.suite.yml (although I think it shouldn't relate to this config):

WebDriver:
    browser: chrome
    url: 'http://app.test'

The second issue, yes, the canSeeLink passes even I see the browser is accessing http://app.testso I think the Edit link should be http://app.test/edit/1, and it shouldn't pass. Moreover, I tried to change the code to:

$I->canSeeLink('Edit', '/whatever');

and it still PASSES! Come on....

Does anyone know what the problem is?

14 Nov
3 years ago

xdimension left a reply on $http.post Doesn't Work

I had removed csrf middleware for the route, so I don't think csrf token will raise the issue. Anyway, it doesn't even send the POST request.

xdimension started a new conversation $http.post Doesn't Work

Hi,

I have a list that can be sorted by users and after sorting the list items the order should be saved. I'm using RubaXa/Sortable to do the sorting.

Here is part of my code (I only put code related to this issue):

myList = new Vue({

data: {
    listData: []
},

ready: function() {
                this.getTheList(); 
            },

methods: {
                getTheList: function() {

                    this.$http.get(url, function(data) {
                        this.listData = data;

                    }).success(function() {
                        Sortable.create(listing, {
                            onEnd: function(e) {
                                myList.updateTheList(e.oldIndex, e.newIndex);
                            }
                        });
                    });
                },

        updateTheList: function(from, to) {
                    this.listData.splice(to, 0, this.listData.splice(from, 1)[0]);

                    this.$http.post(url, this.listData, function() {
                         alert('listing order saved');
                    });
                }
}

So the process is, first I'm getting the list data from server then call Sortable to activate sorting for the list, and if user sorts some items, on the end of dragging the item I call updateTheList method that contains $http.post to send the order of the list to server.

Everything works fine except the $http.post, there was no post being called, but the alert that I put there shows up. So, what am I missing here?

24 Oct
3 years ago

xdimension left a reply on Transfer Server To Another Forge Account

@prograhammer Sorry, forgot to update this thread. Yes, I contacted Forge support and Taylor answered me that he would be able to do the transfer.

30 Sep
3 years ago

xdimension left a reply on Transfer Server To Another Forge Account

Hi @jekinney

Thanks for your reply. Yeah, I had a thought of using the Forge Plus plan too, but I think it's for sharing between team members and it means I still have access to the server where in this case I may need to completely transfer to their account. Anyway, I just asked to Forge support, let's see if there is any solution for this issue.

xdimension started a new conversation Transfer Server To Another Forge Account

Hi,

Supposed my client has their own DO account and they ask me to deploy their website which I can do it from my Forge account. My question, when they want to have their own Forge account later (maybe they hire their own person to manage the server), how do I transfer the server from my Forge to theirs without re-provisioning the server?

15 Sep
3 years ago

xdimension left a reply on Codeception Questions

Hi,

I have a test for a form with PUT / PATCH method and it's working well in Codeception functional test. I'm not sure if it helps, but I have the submitForm part in the Cest class itself, also I include the Laravel5 module in the functional.suite.yml.

xdimension left a reply on Language Support

They may save the chosen language to the settings table, and then retrieve the language setting before calling App::locale() (please see here http://laravel.com/docs/5.1/localization).

Example in a simple route:

Route::get('welcome', function () {
    $settings = Settings::first(['language']);
        App::setLocale($settings->language);

        //
});

or you may put it in a middleware I think, so you don't need to repeat it everywhere in routes or controllers.

08 Sep
3 years ago

xdimension left a reply on Vue JS - Displaying List: Check If The Object In The List Is Null

Maybe you can use v-if directive like this:

<td v-if="document">@{{ document }}</td>
<td v-if="!document"><button></td>

xdimension left a reply on User Model Factory Error

@Jmrtech When you run the following code in your test:

    factory(App\Hospital::class)->create();
        
        $user = factory(App\User::class)->create();

the first line will create a row in the hospital table, with an auto incremented id (I assume). When you create a user from the factory, you need to override the hospital_id with id of the hospital that you had created (the code is in my previous post), thus the user row will be linked to the hospital row. Otherwise the id in hospital table will keep incremented, and since you assign hospital_id to 1 in user factory model, then the foreign key constraint will squawk as it couldn't find the primary key (the row with id = 1 in the hospital table has been deleted on 2nd run when you're using database transaction).

That's what I see in your code that you provided here, unless there is something else which caused the issue.

07 Sep
3 years ago

xdimension left a reply on User Model Factory Error

You need to assign the hospital_id from hospital row that you had created before.

$hospital = factory(App\Hospital::class)->create();
...
$user = factory(App\User::class)->create([
    'hospital_id' => $hospital->id
]);
06 Sep
3 years ago

xdimension left a reply on Laravel 5 Making The Queue Listener To Handle Jobs Pushed By An External Entity

How do I look into the structure of a job that my laravel app can handle? Maybe you can set the queue driver to database, try to queue a job from Laravel and check the job structure in the payload column.

03 Sep
3 years ago

xdimension left a reply on Use Existing Database To Generate Migrations

I used https://github.com/Xethron/migrations-generator for generating migrations. It worked like a charm.

30 Aug
3 years ago

xdimension left a reply on Call To Undefined Method Illuminate\Database\Eloquent\Collection::movie()

Where did you get $id? Is $file correctly populated?

25 Aug
3 years ago

xdimension left a reply on Struggle Bus, With Event Listeners And Tracking User Login And Log Out.

Basically, you need to write what the listener will be doing in the handle method, such as:

class UserLoginListener
{
    public function handle($user)
    {
        Log::info("User {$user->name} logged in");
    }
}

Then, in the EventServiceProvider you register the auth.login and auth.logout events with each listener like you did above:

protected $listen = [
    'auth.login' => [
        'App\Listeners\UserLoginListener'
    ],
    // the same as for 'auth.logout'
];

xdimension left a reply on Codeception Little Problem

@Mithridates I tried on my test, and found that it's working case insensitively, also it works partially for the text in assertion.

As your example, you have "Unfollow OtherUser" on the page, then:

$I->see('unfollow otheruser'); // pass
$I->see('follow otheruser'); // pass, because I see "follow otheruser" in "unfollow otheruser"
$I->dontSee('unfollow otheruser'); // not pass, because I expect not to see "unfollow otheruser", but I see it
$I->dontSee('follow otheruser'); // not pass, because I expect not to see "follow otheruser", but I see it in "unfollow otheruser"
24 Aug
3 years ago

xdimension left a reply on Is It Possible To Mock Model::find()?

@bobbybouwmann Thanks for your reply. I have just tried this:

        $project = m::mock('StdClass');
        $project->id = 1;

        $task = m::mock('App\Task');
        $task->project = $project;

    $this->app->instance('App\Task', $task); 

got no luck, it raised an error "Method Mockery_1_App_Task::setAttribute() does not exist on this mock object", it must be this line $task->project = $project caused the trouble and I don't think I want to set an attribute here.

I also tried:

        $project = m::mock('StdClass');
        $project->id = 1;

        $task = m::mock('StdClass');
        $task->project = $project;
    $task->shouldReceive('find')->once()->andReturn($task);

    $this->app->instance('App\Task', $task); 

It seemed to work, but it failed in asserting $subTask->project_id equals to 1.

Anyway, I'm curious, is the trouble becauseTask::find is actually a static call? If it is so, I'm wondering what is the workaround for this case?

xdimension left a reply on Building A CLI App With Laravel

@Avram Unless I misunderstood your requirement, I think Laravel has a way to do that http://laravel.com/docs/5.1/scheduling, and Jeffrey has a tutorial for this https://laracasts.com/series/intermediate-laravel/episodes/1

xdimension started a new conversation Is It Possible To Mock Model::find()?

Hi,

I have this code and I want to test that the model's attributes are assigned properly:

class SubTask extends Model
{
    public function add($data)
    {
        $this->fill($data);

        $task = Task::find($data['parent_task_id']);

        $this->project_id = $task->project->id;

        $this->save();
    }
}

Is it possible to mock Task::find so it can provide mocked $task object where I can set $task->project->id?

Here is the test that I'm thinking of:

    public function add_subtask()
    {
        $data = [
            'name' => 'Subtask One',
            'parent_task_id' => 1
        ];

        // need to mock Task::find here

        $subTask = m::mock('SubTask')->makePartial();
        $subTask->shouldReceive('save')->once();

        $subTask->add($data);

        $this->assertEquals($subTask->name, $data['name']);
        $this->assertEquals($subTask->project_id, $task->project->id);      
    }
15 Aug
3 years ago

xdimension left a reply on Admin With Laravel 5.1

I did a quick search for "laravel roles" in github and got some packages that looks nice, it seems they work with L5/L5.1 as well: https://github.com/pingpong-labs/trusty https://github.com/artesaos/defender

just for alternatives...

11 Aug
3 years ago

xdimension left a reply on Admin With Laravel 5.1

Hi,

I think the easiest way is adding a column like 'is_admin' in users table, then using middleware you can filter all routes that are only available for admin user. However this approach is not flexible enough, for example you cannot have different roles for each admin user, the good news is there are some laravel role packages in github that provide this functionality.

HTH.