vendredi 29 juillet 2016

Access authenticated user in route binding (L5.2)

Is it possible to access the authenticated user in a route binding.

Route::bind('account', function($account_id)
{
    dd(auth()->user()); // it's null :(

    $account = App\Models\Account::where('business_id', auth()->user()->business_id)
        ->where('account_id', $account_id)
        ->first()

    return !is_null($account) ? $account : App::abort(404);
});

I've tried grouping the route binding in some auth middleware, no dice - is this a thing? It would be really useful to pull off, to avoid extra validation in the controller.

Help appreciated.



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

Trying to avoid pushing duplicates into array Angular

I have a Laravel 5.1 and Angular app.

I am returning a collection of objects to Angular from my Laravel controller. I am then trying to push new objects onto that scope variable but want to avoid pushing a duplicate.

The returned collection looks like this;

$scope.albums = [
{"id": 1,
 "name": "Pork Soda",
 "band": "Primus"}
{"id": 2,
 "name": "Fly by Night",
 "band": "Rush"}
{"id": 3,
 "name": "Freaky Styley",
 "band": "RHCP"}
]

I then present an ng-repeat of another collection;

$scope.availableAlbums = [
{"id": 1,
 "name": "Pork Soda",
 "band": "Primus"}
{"id": 2,
 "name": "Fly by Night",
 "band": "Rush"}
{"id": 3,
 "name": "Freaky Styley",
 "band": "RHCP"}
{"id": 4,
 "name": "Zenyatta Mondatta",
 "band": "The Police"}
{"id": 5,
 "name": "2112",
 "band": "Rush"}
{"id": 6,
 "name": "Truth and Soul",
 "band": "Fishbone"}
]

Now I have a function that allows the user to add a $scope.availableAlbums to the $scope.albums. The issue is, I do not want to be able to allow for a duplicate album to be added. I am using a unique filter on the repeat which stops a duplicate from being displayed but it doesn't actually stop it from being added to the array.

I have tried an indexOf argument but can't seem to get it to stop the duplicate.

I am trying this right now to find the index of the pushed object and if found don't push;

$scope.addAlbum = function(album) {

    var id = {id: album.id};

    if (!(id in $scope.albums)){
        $scope.albums.push(album);
    }
 }

However, the above is not finding the id when it does exist in the array.

This seems like something that would pretty common place. What am I missing?

Thanks!



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

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`foodsuggestion

I have a table Food having fields:

  • FoodID(PK)
  • FoodName
  • CategoryID(FK)
  • ResID(FK) And other table is Restaurant having fields:
  • ResID(PK)
  • ResName
  • FoodID(FK) When I insert data to any table it gives error like:

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (foodsuggestion.restaurant, CONSTRAINT restaurant_food_id_foreign FOREIGN KEY (Food_id) REFERENCES food (Food_id)) Where is the problem in my DB?I am using llaravel.



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

Proper way to pass a hard-coded value from route to controller (Laravel)?

I have a PagesController with one action: view. This action accepts a page argument.

What I want to achieve:

Have a routes example.com/about and example.com/foobar. When one of this routes is triggered, pass a value predefined in routes file to PagesController@view.

In my routes file:

Route::get('about', function () {
    return App::make('App\Http\Controllers\PagesController')->view('about');
})->name('aboutPage');

Route::get('foobar', function () {
    return App::make('App\Http\Controllers\PagesController')->view('foobar');
})->name('foobarPage');

It works as expected, but I want to know is there a better and more proper way to achieve the same functionality?



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

Forget Password email not working laravel 5

I am using users table column name (EMAIL,PASSWORD).if i am changing to column name(email) as small letters is working fine. To Change column name(EMAIL) as caps is not working give me any suggestion. i am able to login but forget password is not working. please give any suggestion

my function in controller:

 public function postEmail(Request $request)
{
    $this->validate($request, array('email' => 'required|email'));
    $response = $this->passwords->sendResetLink($request->only('EMAIL'), function ($m) {
        $m->subject($this->getEmailSubject());
    });
    switch ($response) {
        case PasswordBroker::RESET_LINK_SENT:
            return redirect()->back()->with('status', trans($response));
        case PasswordBroker::INVALID_USER:
            return redirect()->back()->withErrors(array('email' => trans($response)));
    }
}



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

Sidebar admin LTE laravel 5

Iam using admin LTE in laravel I want to show in dashboard what I click in menu sidebar I want do it with routes.php, but is showing in another page, please help me. How I do that?



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

What is the differnece between these two back() methods in laravel 5.2?

I have tried both the back methods but i don't know which one is better or what is the difference between them.

function foo(Request $request){

    /*1st back method*/
    return back();

    /*2nd back method*/
    return redirect()->back();

}



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