lundi 27 février 2017

Dynamic Subcategories Navigation with category and subcategory slug laravel

I have a table in MySQl that contains list of all categories and subcategories. Each subcategory includes assigned parent_category_id

The page controller is as follows:

Route::get('/', 'PageController@home');
Route::get('{category}', 'PageController@category_show');
Route::get('{category}/{subcategory}', 'PageController@subcategory_show');

Now to the main part of the question, I am trying to create Top Navigation and Sidebar Navigation for subcategories. The top navigation is pretty simple and this is how I managed to accomplish this in my NavigationComposer.php

class NavigationComposer
{
    public function compose(View $view)
    {
        $view->with('categories', \App\Category::where(
            array(
            'category_display_type' => 'header',
            'category_visibility' => 1
        ))->get());
    }
}

I have tried to do the same with my subcategories in my SidebarnavComposer.php All works just fine except that I need to have the category slug in the URI when I switch to one of the categories. So far I am only able to get parent_category_id in URI. I have tried to create a join, but getting some errors.

Here is the content of my SidebarnavComposer.php

class SidebarnavComposer
{
    public function compose(View $view)
    {
        $view->with('subcategories', \App\Category::where(
            array(
            'category_display_type' => 'sidebar',
            'category_visibility' => 1
        ))->get());

    }

}

I am new to Laravel so please help me if you can.

Thanks in advance



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2lqI3dx
via IFTTT

How laravel `Auth:user()` or `Auth:id()` works

How laravel Auth:user() or Auth:id() works

Is it resides in session or database.

I searched but not get good article.

Please help to understand. I know I will get many down-votes ;)



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2m2hPl5
via IFTTT

Update records hierarchy

I need to update herarchies, for example one parent has points 5 then its children's point will increase by +5 and so on till the end.

I am not sure what should I user here should do this in mysql or laravel ? which is the best option and also I could like to know if anyone has any good example like this.

looking for some good Idea on this, Thanks in advance



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2l3kqvx
via IFTTT

Query if a relationship exists with conditions in Laravel

I have a model Foo that contains a hasMany relationship to Bar.

I have a query similar to the following:

$r = Foo::with(['bar' => function($query) {
    $query->where('someProp', '=', 10);
})->get()

However, I want to only return the Foo object if item has a Bar object that satisfies the query.

I'm aware that you can do something like this:

$r = Foo::has('bar')
    ->with(['bar' => function($query) {
        $query->where('someProp', '=', 10);
    })->get();

But that checks if any bar items exists. Not if a bar item exists with someProp = 10

How can I do this?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2lqtI0t
via IFTTT

What is the best way to push data into mobile devise?

Hello stack community !

I work on Ionic 2.0 with Laravel.php as backend. And I have a simple question :

What is the best way to push data into mobile devise ?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2lXwugP
via IFTTT

Auth Issue when upgrading from Laravel 5.2 to Laravel 5.3

I have following the official guide to upgrade from laravel 5.2 to laravel 5.3: http://ift.tt/29vUJ0Q

Because I needed some customizations to the default authentication I have copied the login function to Http\Controllers\Auth\AuthController.php.

Now, when I updated, the `AuthController.php' was divided into several other files.

I have copied the login function to Http\Controllers\Auth\LoginController.php

Now, I am getting the following error when trying to login:

BadMethodCallException in Controller.php line 82:

Method [getCredentials] does not exist.

The login functions below (Might not matter):

public function login(Request $request)
{
$this->validate($request, [
    'email' => 'required|email', 
    'password' => 'required',
]);

$credentials = $this->getCredentials($request);

// This section is the only change
if (Auth::validate($credentials)) {
    $user = Auth::getLastAttempted();
    if ($user->active) {
        Auth::login($user, $request->has('remember'));

        ActivityLog::add("User has successfully logged in.", $user->id);

        return redirect()->intended($this->redirectPath());
    } else {
        return redirect($this->loginPath) // Change this to redirect elsewhere
            ->withInput($request->only('email', 'remember'))
            ->withErrors([
                'active' => 'This account has been suspended.'
            ]);
    }
}

return redirect($this->loginPath)
    ->withInput($request->only('email', 'remember'))
    ->withErrors([
        'email' => $this->getFailedLoginMessage(),
    ]);

}

How do I fix this?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2mC9nFH
via IFTTT

Laravel 5.3 how to write custom casted attribute

I have Trait for custom cast types and added currency cast type but it works only when accessing attribute:

trait ModelCastsTrait {

protected function castAttribute($key, $value)
{
    if (is_null($value)) {
        return $value;
    }

    switch ($this->getCastType($key)) {
        case 'int':
        case 'integer':
            return (int) $value;
        case 'real':
        case 'float':
        case 'double':
            return (float) $value;
        case 'string':
            return (string) $value;
        case 'bool':
        case 'boolean':
            return (bool) $value;
        case 'object':
            return $this->fromJson($value, true);
        case 'array':
        case 'json':
            return $this->fromJson($value);
        case 'collection':
            return new BaseCollection($this->fromJson($value));
        case 'date':
        case 'datetime':
            return $this->asDateTime($value);
        case 'timestamp':
            return $this->asTimeStamp($value);
        case 'currency':
            return new CurrencyCast($value, $this);
        default:
            return $value;
    }
}

}

How make custom attribute casting work in reverse, convert value to castable type?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2mv6Wpw
via IFTTT