jeudi 26 novembre 2015

convert to nested format php

I just want some help in displaying the correct structure of the image data below. Basically what i want is to display it in nested form. From the data below, I would like it to display like this:

  • Engel (parent which parent_id = 0)
    • Chest Fridge - Freezers
      • Small Engel
      • digital platinum
    • Upright Fridge
      • Built-in fridge
    • Fridge Accessories
      • Blankets
      • Carry handles

enter image description here

I hope anyone can help me. Im using php fyi.



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

laravel 5.1 auth.login event triggered twice

Im building my app with laravel, and i create logger that log user login to mysql database, i used built in event auth.login, and then this is my code in class EventServiceProvider

This is my EventServiceProvider.php

protected $listen = [
    'App\Events\UserFailedLoggedInEvent' => [
        'App\Listeners\UserFailedLogginLogger',
    ],

];

/**
 * Register any other events for your application.
 *
 * @param  \Illuminate\Contracts\Events\Dispatcher  $events
 * @return void
 */
public function boot(DispatcherContract $events)
{
    parent::boot($events);

    $events->listen('votee.*', function($user, $voteable, $counter){
        $voteable->vote_down = $counter->down;
        $voteable->vote_up = $counter->up;
        $voteable->save();
    });

    $events->listen('mural.comment.add', function($comment, $content, $author, $room){
        $content->increment('comment');
    });

    $events->listen('mural.comment.remove', function($comment, $user){
        $comment->commentable->decrement('comment');
    });

    $events->listen('auth.logout', 'App\Listeners\UserLogoutLogger@handle');

    $events->listen('auth.login', 'App\Listeners\UserLoginLogger@handle');

}

}

And this is my App\Listeners\UserLoginLogger, i use spatie/activitylog

public function handle()
{
    Activity::log("Logged In");
}

but it will save to the database two login activity.



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

How to create a user in seeder in Laravel - Password not working?

I am trying to create a seeder in laravel. So far I have the following:

User::create([
      'name' => 'John Smith'   
      'email' => 'john@example.com',
      'password' => 'letmein',
]);

However this does not seem to work when logging in as this user. What am I doing wrong?



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

Laravel 5 - creating two tables during registration

In my database design, I have two tables, People & Auth. The Auth table holds authentication information and the person_id while the People table holds all other information (name, address, etc). There is a one-to-one relationship between the tables as seen in the models below.

The reason I have separated the data into two tables is because in my application, I will have many people who do not have authentication capabilities (customers to the user).

App/Auth.php

   class Auth extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract
    {
        use Authenticatable, Authorizable, CanResetPassword;

        public function person() {
            $this->belongsTo('Person');
        }
    }

App/Person.php

class Person extends Model
{
    public function auth() {
        $this->hasOne('Auth');
    }
}

In my AuthController::create() method, I am attempting to populate both models with the user supplied information like this:

protected function create(Request $request)
    {
        $person = \App\Person::create($request->all());

        $auth = new \App\Auth;
        $auth->fill($request->all());
        $auth->person_id = $person->id;
        $auth->save();

        return $person;
    }

In my application, I would like to authorize a user and pass a $user object as the authenticated person to subsequent routes. Am I doing this correctly? Is this the best way? There's cookies and bonus points if you can also explain how to retrieve the $user object after authentication...Auth table data is not needed in the $user object.



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

Laravel header CORS

Problem

When I go to the url http://api.example.com through my browser (Chrome), it shows me this, with correct headers (notice the Access-Control-Allow-Origin field)

enter image description here

But when I do a post request to http://api.example.com from http://test.example.com, it shows me this enter image description here

And the console shows me

XMLHttpRequest cannot load http://ift.tt/1T8hGTP. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://test.example.dev' is therefore not allowed access. The response had HTTP status code 500.

What I did

I'm using the framework Laravel 5 and I followed this tutorial to add header to responses. I copied exactly the piece of code of the tutorial. What is still wrong here ?

Here is my routes file :

enter image description here

And my Cors Middleware file : enter image description here



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

Laravel 5 jenssegers MongoDB and Fire / Listener fails on undefined builder::fire

Anyone out here used the Jenssegers MongoDB in Laravel that have succesfully setup events and listeners with it?

I have an event and listener set up with php artisan, and when I add a Fire to execute an event I get the following error:

BadMethodCallException in Builder.php line 2071:
Call to undefined method Jenssegers\Mongodb\Query\Builder::fire()

This is my entire stack trace:

in Builder.php line 2071
at Builder->__call('fire', array(object(TicketHasBeenBought))) in Builder.php line 1058
at Builder->__call('fire', array(object(TicketHasBeenBought)))
at Builder->fire(object(TicketHasBeenBought))
at call_user_func_array(array(object(Builder), 'fire'), array(object(TicketHasBeenBought))) in Builder.php line 943
at Builder->__call('fire', array(object(TicketHasBeenBought)))
at Builder->fire(object(TicketHasBeenBought))
at call_user_func_array(array(object(Builder), 'fire'), array(object(TicketHasBeenBought))) in Model.php line 3482
at Model->__call('fire', array(object(TicketHasBeenBought))) in Model.php line 537
at Model->__call('fire', array(object(TicketHasBeenBought)))
at Event->fire(object(TicketHasBeenBought))
at call_user_func_array(array(object(Event), 'fire'), array(object(TicketHasBeenBought))) in Model.php line 3496
at Model::__callStatic('fire', array(object(TicketHasBeenBought))) in Orders.php line 227
at Event::fire(object(TicketHasBeenBought)) in Orders.php line 227
at Orders->store(object(Request))
at call_user_func_array(array(object(Orders), 'store'), array(object(Request))) in Controller.php line 256
at Controller->callAction('store', array(object(Request))) in ControllerDispatcher.php line 164
at ControllerDispatcher->call(object(Orders), object(Route), 'store') in ControllerDispatcher.php line 112
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114
at ControllerDispatcher->callWithinStack(object(Orders), object(Route), object(Request), 'store') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\Orders\Orders', 'store') in Route.php line 203
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 712
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 714
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 679
at Router->dispatchToRoute(object(Request)) in Router.php line 639
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in xdomain.php line 23
at xdomain->handle(object(Request), object(Closure))
at call_user_func_array(array(object(xdomain), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 54
at require_once('/var/www/vhosts/prepay/httpdocs/public/index.php') in server.php line 21



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

Laravel get_file_contents() replaces & with &

How can I avoid Laravel replacing & with & when calling get_file_contents()? I always get a "Bad Request" response because of this, which is not a problem when not using Laravel.



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