dimanche 28 août 2016

How can I get sessions created earlier in laravel

I need to sort my sessions by created earlier in Laravel, And I don't use session table. To do this you have any suggestions? I don't know by filename or any ? thanks all and sorry for my terrible English grammer.



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

Convert Mysql Query to Laravel 5 Eloquent

I am using Laravel 5.1 in my application. My MySQL Query is

$result = DB::select(DB::raw("Select * from "
            . "(Select u.* from "
            . "( "
            . "SELECT u2.id as user_id, u2.fname as fname, u2.lname as lname, u2.uname as uname, u2.email as email, u2.address as address, u2.city_id as city_id, u2.website as website FROM users u1, users u2 where u1.city_id = u2.city_id && u1.id = '$this->current_user_id' ) 
                u left join follows f on u.user_id = f.following_id where f.following_id is null 
                UNION
                Select uu.id as user_id, uu.fname as fname, uu.lname as lname, uu.uname as uname, uu.email as email, uu.address as address, uu.city_id as city_id, uu.website as website from users uu where uu.id in (Select u.user_id from (SELECT user_id FROM reviews group by user_id order by count(user_id) desc5
                ) u left join follows f on u.user_id=f.following_id where f.following_id is null
                )
                ) 
                T LIMIT 5"
    ));

How Can I convert it in Laravel Eloquent?



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

Laravel 5.2 - Sweet Alert confirmation box

I have Categories listed in a view. A delete category button is also there in the view which does work and deletes the category when clicked.

What I want to do is before deleting a category, a sweet alert dialog to pop up and ask for confirmation. If confirmed, it should go to the defined route and delete the category.

The delete link is defined like this:

<a id="delete-btn" href="" class="btn btn-danger">Delete</a>

and the script is defined like this:

<script> 
    $(document).on('click', '#delete-btn', function(e) {
        e.preventDefault();
        var link = $(this);
        swal({
            title: "Confirm Delete",
            text: "Are you sure to delete this category?",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "Yes, delete it!",
            closeOnConfirm: true
         },
         function(isConfirm){
             if(isConfirm){
                window.location = link.attr('href');
             }
             else{
                swal("cancelled","Category deletion Cancelled", "error");
             }
         });
    });
</script>

However, when I click the delete button it deletes the category, but the sweet alert message doesn't show up.

The route is defined as following:

Route::get('/categories/destroy/{category}', [
    'uses' => 'CategoriesController@destroy',
    'as' => 'admin.categories.destroy',
]);

and the controller function is defined as:

public function destroy(Category $category) 
{

    $category->delete();

    //this alert is working fine. however, the confirmation alert should appear 
    //before this one, which doesn't
    Alert::success('Category deleted successfully', 'Success')->persistent("Close");

    return redirect()->back();
}

Any help would be appreciated. Thanks.



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

samedi 27 août 2016

How injecting a array in my view with laravel 5 using a facade and the App:make method in the view

I created a facade that works well, a using service container :

My class :

namespace App\Classes;

class Administration {

  public function message_success()
{
   $message = "success";

  return $message;

  }

}

My view :

Résultat Ok

But when I want to work with a array, I can not retrieve a value in my view with App::make.

My class :

namespace App\Classes;

class Administration {

public function message_test($message, array $type = array())
{

  $type = ['message1' => 'valeur1', 'message2' => 'valeur2'];

  return $message;

  }

}

How to build the syntax in my view?



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

POST controller for all routes in Laravel 5

I have callback button in header of my webpage, so user can send me message from every page. How to make route for this? Something like that:

Route::post('{*}', 'PostController@callback');



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

Return result after the event is fired in Laravel 5.2

My original code is below

/*
   Create the Role
*/  

$result = (new RoleDb())->Create($obj);

if($result["Success"]) {

    /*
    | Get all Modules 
    */

    $Permissions = $this->Module->All($obj->RoleID);
    $list = [];

    /*
    | Prepare the list that will be assigned to Newly created role.
    */

    foreach($Permissions["Data"] as $Permission) {
        $RolePermissionOM = new RolePermissionOM();
        $RolePermissionOM->PermissionID             = $Permission->PermissionID;
        $RolePermissionOM->IsActive                 = $Permission->DefaultPermission;
        $RolePermissionOM->RoleID                   = $result["Data"];
        array_push($list, $RolePermissionOM);
    }

    /*
    | Create default permissions for above created role.
    */

    return $this->RolePermission->CreateDefaultPermissions($list, $result["Data"]);
}

Now, in my application, there are 3 more points where role is being created and instead of code duplication, I though to convert this code into event. SO whenever a role is being created, an Event is being fired to create the permission records for that role.I wrote the below code.

Event::fire(new RoleCreationEvent($result));
// `$result` contains the newly created RoleID.

Question : In my original code, I was able to get the result to check if the permissions are saved correctly or not. How will I do that in case of firing the Event ?



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

Angular2 Can't see my custom headers attached

I am trying to attach a custom Authorization header to my get requests in my angular2 app.

Here's my code:

private headers : Headers;
  constructor (private http: Http)
  {
    this.headers = new Headers();
    //this.headers.append('Content-Type', 'application/json');
    let jwt = localStorage.getItem('id_token');
    if(jwt)
      this.headers.append('Authorization', 'Bearer ' + jwt);
  }

  private journalsUrl = Config.API_URL + 'journal';  // URL to web API

  getJournals (): Observable<Journal[]>
  {
    return this.http.get(this.journalsUrl, { headers: this.headers })
                    .map(this.extractData)
                    .catch(this.handleError);
  }

I made sure that my laravel 5 with barryvdh/laravel-cors server allowed pretty much everything related to headers:

'supportsCredentials' => false,
'allowedOrigins' => ['*'],
'allowedHeaders' => ['*'],
'allowedMethods' => ['*'],
'exposedHeaders' => ['Authorization'],
'maxAge' => 0,
'hosts' => [],

As I debug when I look at the networks tab in google chrome looking at the headers of that particular request that fails I see: General:

Request URL:http://ift.tt/2bGZPHq
Request Method:OPTIONS
Status Code:401 Unauthorized
Remote Address:127.0.0.1:80
Response Headers

Request Headers:

Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8,ar;q=0.6
Access-Control-Request-Headers:authorization
Access-Control-Request-Method:GET
Connection:keep-alive
Host:api.ketabuk.dev
Origin:http://localhost:3000
Referer:http://localhost:3000/
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36

Notice that: Access-Control-Request-Headers:authorization. But notice also that the Authorization field itself is not there.

What am I doing wrong?



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