miso

miso

Member Since 4 Years Ago

Experience Points 8,015
Experience Level 2

1,985 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 70
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.

13 Sep
10 months ago

miso left a reply on Redirect To Page If Validation Fails When Trying To Login Or Register

Hi, in Laravel 5.6 you can do this:

In the trait AuthenticatesUsers there is this function

    public function login(Request $request)
    {
        $this->validateLogin($request);

        // If the class is using the ThrottlesLogins trait, we can automatically throttle
        // the login attempts for this application. We'll key this by the username and
        // the IP address of the client making these requests into this application.
        if ($this->hasTooManyLoginAttempts($request)) {
            $this->fireLockoutEvent($request);

            return $this->sendLockoutResponse($request);
        }

        if ($this->attemptLogin($request)) {
            return $this->sendLoginResponse($request);
        }

        // If the login attempt was unsuccessful we will increment the number of attempts
        // to login and redirect the user back to the login form. Of course, when this
        // user surpasses their maximum number of attempts they will get locked out.
        $this->incrementLoginAttempts($request);

        return $this->sendFailedLoginResponse($request);
    }

Take this function and insert it into LoginController

Then modify the function like this:

    public function login(Request $request)
    {
        try {

            $this->validateLogin($request);

            // If the class is using the ThrottlesLogins trait, we can automatically throttle
            // the login attempts for this application. We'll key this by the username and
            // the IP address of the client making these requests into this application.
            if ($this->hasTooManyLoginAttempts($request)) {
                $this->fireLockoutEvent($request);

                return $this->sendLockoutResponse($request);
            }

            if ($this->attemptLogin($request)) {
                return $this->sendLoginResponse($request);
            }

            // If the login attempt was unsuccessful we will increment the number of attempts
            // to login and redirect the user back to the login form. Of course, when this
            // user surpasses their maximum number of attempts they will get locked out.
            $this->incrementLoginAttempts($request);

            return $this->sendFailedLoginResponse($request);
            
        } catch (\Illuminate\Validation\ValidationException $e) {

            return redirect()->route('login')
                ->withInput($request->all())
                ->withErrors($e->validator);

        }

    }

It will catch all validation exceptions which the code can generate (validation, lockout and wrong credentials). Then it will redirect with previous input data and with errors from the validation object.

04 Sep
2 years ago

miso started a new conversation Passport - Replacement For User Authentication?

Hi, is it a good idea to use Passport just for user authentication? I have my own (first-class) client Javascript application, so I can create new oauth Password Grant Client. Docs say:

$response = $http->post('http://your-app.com/oauth/token', [
    'form_params' => [
        'grant_type' => 'password',
        'client_id' => 'client-id',
        'client_secret' => 'client-secret',
        'username' => '[email protected]',
        'password' => 'my-password',
        'scope' => '',
    ],
]);

But how and where to hide the client_secret? It is javascript app and anyone can see its source code - after that it can simulate my app/first-party client. The second question is how can Password Grant Tokens work with multiple devices/browsers? Can be user authenticated in multiple browsers? Thank you

12 Jun
3 years ago

miso left a reply on Encrypting Model Data

The accepted answer works but it is not complete.

Model has attributesToArray() method which does not call getAttribute() method, so if you run attributesToArray() it will not decrypt data.

You have to define attributesToArray() in the trait:

    public function attributesToArray()
    {
        $attributes = parent::attributesToArray(); // call the parent method

        foreach (static::$encryptable as $key) {

            if (isset($attributes[$key])){

                    $attributes[$key] = Crypt::encrypt($attributes[$key]);

            }
        }
        return $attributes;
    }
08 Jun
3 years ago

miso left a reply on Multiple Config:cache Do Not Work

I solved it:

modifyAndSaveDotenv();
// delete cached config.php
$this->call('config:clear');
// load .env file to memory (must be overload() which works in mutable mode)
(new \Dotenv\Dotenv($this->laravel->environmentPath(), $this->laravel->environmentFile()))->overload();
// load configuration from cache or config files (cache was deleted therefore config files are used)
// this works because config files take data with env() !
$this->laravel->bootstrapWith(['Illuminate\Foundation\Bootstrap\LoadConfiguration']);
// create config.php again
$this->call('config:cache');
// repeat commands!

miso left a reply on Multiple Config:cache Do Not Work

// delete cached config.php $this->call('config:clear'); // load .env file to memory (must be overload() which works in mutable mode) (new \Dotenv\Dotenv($this->laravel->environmentPath(), $this->laravel->environmentFile()))->overload(); // load configuration from cache or config files (cache was deleted therefore config files are used) // this works because config files take data with env() ! $this->laravel->bootstrapWith(['Illuminate\Foundation\Bootstrap\LoadConfiguration']); // create config.php again $this->call('config:cache'); // repeat commands!

miso left a reply on Multiple Config:cache Do Not Work

I solved it:

// delete cached config.php
$this->call('config:clear');
// load .env file to memory, (must be overload() which works in mutable mode)
 (new \Dotenv\Dotenv($this->laravel->environmentPath(), $this->laravel->environmentFile()))->overload();
// load configuration from cache or config files (cache was deleted therefore config files are used - and they works with env() ! )
$this->laravel->bootstrapWith(['Illuminate\Foundation\Bootstrap\LoadConfiguration']);

miso started a new conversation Multiple Config:cache Do Not Work

Hi, I do this:

modifyAndSaveDotenvFile();
$this->call('config:cache');

This works fine, the app/bootstrap/cache/config.php is updated.

However when I do this several times, the cached file is not updated.

modifyAndSaveDotenvFile();
$this->call('config:cache');
modifyAndSaveDotenvFile();
$this->call('config:cache');

I do this in my console app and call multiple commands, it is not in one call as in example.

14 May
3 years ago

miso started a new conversation Transactional Activity Feed / Audit

Hi, there is nice video how to implement RecordsActivity trait which uses Model events and inserts data to the database on various events: https://laracasts.com/lessons/build-an-activity-feed-in-laravel and https://github.com/laracasts/Build-An-Activity-Feed-in-Laravel I would like to make it transactional (always store audit data or do not store the subject in the end), but I am not sure how to implement it with the model events.

Thank you for suggestions.

09 May
3 years ago

miso started a new conversation Fractal Transformer - Include + With()

Hi, I have models and transformers for Folder, User and Access (Access wraps pivot table folder_user).

This include works fine:

class FolderTransformer extends TransformerAbstract {
    ...
    public function includeAccesses(Folder $folder)
    {
        return $this->collection($folder->accesses, new AccessTransformer);
    }

I would like to include user info (name, email, ...) in the Access include.

I tried this naive code, but it does not work:

    public function includeAccesses(Folder $folder)
    {
        return $this->collection($folder->accesses()->with('user')->get(), new AccessTransformer);
    }

FatalErrorException in Builder.php line 638: Call to a member function addEagerConstraints() on null

05 May
3 years ago

miso started a new conversation Properly Remove Object From Map/object

Hi, I have

// data structure
data: {
    records: null
}
// loading the records:
var map = {};
for (var i = 0; i < response.data.length; i++) {
    map[response.data[i].record_id] = response.data[i];
}
this.records = map;
```

I want to remove object from this.records[k]. This works so far, but I am not sure if this is correct because the two operations are not atomic. Could it throw error when this.records are used in v-for?

this.reco`rds[record_id] = null; // this will notify the watcher delete this.records[record_id]; // this will remove key and value from the map/object.


What is the best practice for this? Thank you

miso left a reply on V-attr="type: ..."

Thanks, I did

<input v-bind:type="password.type">

But when I call

        showPassword: function() {
            // default is 'password'
            this.password.type = 'text';
        },

It does not update the input element.

miso started a new conversation V-attr="type: ..."

Hi, I would like to change type attribute on element.

v-attr="type: record.type"

But: [Vue warn]: Failed to resolve directive: attr.

30 Apr
3 years ago

miso left a reply on Blade Equivalent Isset($v) ? 'string'.$v : ''

It looks like Blade do not support this. Anyway, better practice is to done this with CSS

        .name_alt:not(:empty):before{
            content: ' / ';
        }

miso started a new conversation Blade Equivalent Isset($v) ? 'something' : ''

Hi, I have this, but I want the slash / be included only if $block->name_alt is set and nonempty. Is it possible with Blade?

{{ $block->name }} / {{ $block->name_alt }}

miso left a reply on Builder::select(['id', 'NOW()']) Escape And Not Escape

Okay I wound it

Builder::selectRaw($expression, array $bindings = [])

miso started a new conversation Builder::select(['id', 'NOW()']) Escape And Not Escape

Hi, I would like to select some attributes and current timestamp. But the function NOW() is escaped. Is there any way how to escape some data and some not?

DB::table('blocks')->select(['id', 'NOW()'])->join(...

Thank you

27 Apr
3 years ago

miso started a new conversation Elixir('css/app.css') Poins To Build Folder

Hi, elixir('css/app.css') points to http://localhost/project1/public/build/css/app-abf16cc30b.css

Is it intended? This is my gulpfile.js

elixir(function(mix) {
    mix.sass('app.scss')
        .version('css/app.css');
});
23 Apr
3 years ago

miso left a reply on Override Model::setRawAttributes

Both get_class() and get_class($this) return Mymodel when i call $model->setRawAttributes([]); in controller and also when $model is returned in controller. I am not sure if Laravel calls directly $model->setRawAttributes([]); somewhere. If so, it is game-over.

22 Apr
3 years ago

miso started a new conversation Override Model::setRawAttributes

I want to have setRawAttributes private/protected, but Laravel does not let me declare setRawAttributes as protected/public. I tried this hack, but this does not work... ``` class Record extends Mymodel ... public function setRawAttributes(array $attributes, $sync = false) { if ($this instanceof Mymodel){ // replace Mymodel for self does not work either dd('this should not happen but happens'); return $this; } return parent::setRawAttributes($attributes, $sync); }

16 Apr
3 years ago

miso left a reply on REST API + Many-to-many + Idempotence

@Prez Yes, the ?item=39 approach is REST-OK but the API would not be consistent much for client side programmers (there are many other resources in only /xxxx/id format).

  • Use PUT when you allow the client to specify the resource identifier of the newly created resource. But remember, since PUT is idempotent, you must send all possible values. https://stormpath.com/blog/put-or-post/

So, I would use the PUT|PATCH | users/{users}/items/{items} and the timestamp is probably not a problem: http://stackoverflow.com/questions/5686671/should-i-use-put-method-for-update-if-i-also-update-a-timestamp-attribute

miso left a reply on REST API + Many-to-many + Idempotence

@Prez yes, both are doable, the second one is infact the same as I intended to write (I fixed typo Route::post -> Route::post). But I am not sure it it is OK from REST perspective. I would avoid the first approach because programmers of the client side could be confused from mixing get params with clean urls.

miso started a new conversation REST API + Many-to-many + Idempotence

Hi, I have DB entities User and Item and they have relation many-to-many (user has access to many items and one item is accesible by many users). There are attributes in the pivot table item_user:

  • item_id (composite 1. part)
  • user_id (composite 2. part)
  • created_at (just timestamp)
  • permissions (read/write/modify)

I have Laravel models User and Item which have many-to-many relationship via item_user. I do NOT have Access model for the pivot table (I want composite key only and Laravel does not support composite keys). I want to create symmetric REST API (no "Access" resource):

  • users/x/items/y
  • items/x/users/y (we can forget this for now)

The question is, which of PUT, POST use when I want to link user with item? If I use

  • Route::resource('users.items', 'UserItemController'); then Laravel generates this:
  • POST | users/{users}/items
  • PUT|PATCH | users/{users}/items/{items} Obviously, the first route does not make sense (I want to link existing user with existing item and new item should be created in route POST | items). But, If I use the second line, there is maybe the problem that it is not idempotent as created_at would be changed on each hit. (depends on implementation really, but look at this from REST perspective). Is something wrong with this approach? How should I design the API?

Thank you

21 Jul
3 years ago

miso started a new conversation One-to-zero-or-one Relationship

Hi, is is possible to create one-to-zero-or-one ORM relationship?

Example: offer[offer_id, product_id] product[product_id] Details:

  • offer MUST have exactly 1 product
  • product CAN have 0 offers or 1 offer
  • if product have 0 offers, in the future will have 0 offers

Implementation I am not sure if make FK product_id NULLABLE or make third table offer_product[offer_id,product_id] with UNIQUE constrains.

Thank you

29 May
4 years ago

miso left a reply on AngularJS App - With Lumen Or Laravel?

@SP1966, in the beginning, I do not expect the API be very busy. But lets say, in the future it would be busy as API of airbnb.com. Is it naive to assume that such heavily visited site as airbnb.com can be run on single Laravel app?

@virt, you are right, unauthenticated search queries could target separate API. It it possible to integrate Lumen into Laravel such that they share model layer (repository classes)? Or did you mean different framework instances, perhaps on different machines?

Thank you both for the token advices.

miso started a new conversation AngularJS App - With Lumen Or Laravel?

I am about to build web application consisting of three parts:

  1. Public data-oriented websites for unauthenticated users with geolocation search, ...
  2. Member area (with authentication) for managing the data
  3. Mobile app/apps with the same functionalities

The airbnb.com is a good example of the structure.

Basicaly the thing is to create a server side API which will be shared accross clients.

I definitelly want to use AngularJS for the client side, but I am not sure which of those solutions is better:

  1. Create the API with microframework Lumen and add sessions / authentication / html serving / other services to the Lumen
  2. Create the API with full stack framework Laravel and serve html to AngularJS

Thank you for your suggestions.