ottoszika

Experience

27,150

8 Best Reply Awards

  • Member Since 1 Year Ago
  • 228 Lessons Completed
  • 0 Favorites

18th March, 2018

ottoszika left a reply on Service Provider Register Fix • 6 months ago

Hello,

share method was removed since 5.4. Use:

$this->app->singleton('slug', function () {
    return new Slug;
});

13th March, 2018

ottoszika left a reply on Overriding A Method Implemented In A (used) Trait • 6 months ago

Whenever you are "overriding" a trait method, it will take precedence over the trait's one. Also, you can extend the functionality (like calling the parent method and adding some extra stuffs) by aliasing:

trait RegistersUsers
{
    protected function registered(Request $request, $user)
    {
        echo 'Registered';   // Assuming this was originally in trait.
    }
}
class RegisterController
{
    use RegistersUsers {
        registered as traitRegistered;
    }

    protected function registered(Request $request, $user)
    {
        $this->traitRegistered();
        echo 'Welcome ' . $user->name;
    }
}

Note: Traits are not multiple inheritance. They are a code reuse mechanism, often called mixins in other languages.

ottoszika left a reply on GetRouteByKeyName Another Model Laravel • 6 months ago

Hello,

You can't reference a field from another model, but you can create a route model binding in your RouteServiceProvider like this:

Route::bind('category', function ($value) {
    return optional(CategoriesTranslations::where('alias', $value)->first())->category;
});

Ensure you set up relationships correctly.

Now you can bind in your controller like this:

public function show(Categories $category) {
}

P.S.: Try naming your models singular. It's little bit confusing with plural names :)

6th March, 2018

ottoszika left a reply on How Can I Dynamically Generate "getExampleAttribute()" Functions In A Model Class? • 6 months ago

Hi,

You can override the __call method of the model. Something like this:

protected $fields = [
    // Here you declare the fields you need
];

public function __call($method, $parameters) {
    if (preg_match('/get([^;]+?)Attribute$/', $method, $match)) {
        $property = Str::snake($match[1]);
        if (array_search($property, $this->fields) !== false) {
            return $this->getAttribute($property);
        }
    }
    return parent::__call($method, $parameters);
}
        

5th March, 2018

ottoszika left a reply on Aliases And Undefined Method In Facade • 6 months ago

If you are using facades, the methods should be called statically (see Illuminate\Support\Facades\Facade how it works with it's __callStatic magic method to understand why).

Use WP::autenticate() in this case.

ottoszika left a reply on Laravel Failed To Open Stream: No Such File In Directory • 6 months ago

Maybe it's cached in bootstrap/cache/config.php. Try: php artisan config:clear.

ottoszika left a reply on Laravel Failed To Open Stream: No Such File In Directory • 6 months ago

I see you are using "file" as session driver. Your application is deployed on a Linux server, but you have a Windows-like path set. Please verify your config/session.php file. I think you hardcoded your storage path. Default value for path is:

...
'files' => storage_path('framework/sessions'),
...

ottoszika left a reply on Error • 6 months ago

Laravel 5.6 requires php >= 7.1.5. The error is probably from the following line: public function __construct(?string $test) Nullable types are available only from PHP 7.1: http://php.net/manual/ro/migration71.new-features.php

1st March, 2018

ottoszika left a reply on NewQuery, ToBase, GetQuery • 6 months ago

$model->where('prm_partner_id', 1)->toBase()->toSql(); $model->where('prm_partner_id', 1)->getQuery()->toSql(); The first will apply global query scopes, the second not. To test this quickly, you can use SoftDeletes trait in the model to see the difference.

$model->where('prm_partner_id', 1)->newQuery()->toSql(); The code above creates a new Builder based on the initial one. The same result is obtained with the following: $model->where('prm_partner_id', 1)->toSql();

2nd June, 2017

ottoszika left a reply on Class Settings Not Found In Route.php • 1 year ago

Type with FQN if you don't want to use it (App\Settings::settings()``)`. Also make sure your class is namespaced correctly (namesoace App;```).

ottoszika left a reply on VerifyCRSFToken Except On URL With Query Parameter • 1 year ago

Try overriding the handle method from the base class and add some extra verifications there for your case.

21st April, 2017

ottoszika left a reply on How Can I Delete Records With The Checkbox? • 1 year ago

Put on each row a checkbox with the name "users[]" and the user ID as value. On submitting the form, just take the array and prepare a whereIn query builder and call delete method on it (Hoping you will select only a few number of users, because the generated query will be as long as the selection array, otherwise just loop over each User instance).

public function destroyAll(Request $request)
{
    $selectedIds = $request->input('users');
    User::whereIn('id', $selectedIds)->delete();
}

15th December, 2016

ottoszika left a reply on Update Method Doesn't Save Data To Database • 1 year ago

Are the fields present in the $fillable property of the Comment model?

6th December, 2016

ottoszika left a reply on I Want To Display My Page Numbers At Bottom In Laravel 5.3. • 1 year ago

Where you linked the CSS? I don't see in your index.blade.php. If you linked in a master layout page, this page should extend that layout. https://laravel.com/docs/5.3/blade#extending-a-layout

ottoszika left a reply on I Want To Display My Page Numbers At Bottom In Laravel 5.3. • 1 year ago

Laravel's default pagination presenter is based on Bootstrap. If that's all you have in index.blade.php, you should include the CSS.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.