lundi 1 février 2016

Eloquent model using multiple table query

I have two table Email (id,content,folder_id) Folder (id,name)

In model

public function folder() {
        return $this->belongsTo('App\Folder');
    }

 public function email() {
        return $this->hasMany('App\Email');
    }

In Controller, i want list all email for each folder from a request

public function mailbox ($foldername) {
$data=Email::with('folder')->orderBy('id','DESC')->where('??????',$foldername)->get()->toArray();
        return view('dashboard.mailbox.mailbox',compact('data'));
    }

The probalem is: how can i get name (with ???? in code below) from Folder table to where with input request ->

It's OK if i go with $id request, but i want a beatiful respon, so please help me



via Chebli Mohamed

Laravel 5 - LDAP Authentication

I am using the following library to authenticate users against Active Directory http://ift.tt/20j2J9p

Following the instructions is straight forward, and once I do

$user = Auth::user();

I can see if a user is authenticated. However, in the instructions, it also links to the following http://ift.tt/1P9Viqn

From what I could understand, I thought I could do something like the following

$user = Auth::user()->infoCollection('myusername', array('*'));

However, this returns the error

Call to undefined method Dsdevbe\LdapConnector\Model\User::infoCollection()

This is because infoCollection is not a function defined within the User model. If I want to do what I am attempting above, I would have to do

$options = array(
    'account_suffix'=>'@something.local',
    'domain_controllers' => ['something.local'],
    'base_dn' => 'DC=Mailtrack,DC=local',
    'admin_username' => 'something',
    'admin_password' => 'something'
);

$adldap = new adLDAP($options);
$user = $adldap->user()->infoCollection('someusername', array('*'));

However, if I do this, I am no longer running on the User Model I do not think.

So my main question is, how can I use functions like infoCollection on my User Model?

Thanks



via Chebli Mohamed

how to install sass on Laravel 5

I have a problem with Laravel 5 and SASS. I am trying to use Sass as my style sheets like you would normally do with css. But I am not able to combine them in one laravel project.

The code in public/scss/style.scss

$color_one: green;
$color_two: yellow;

body {
  background-color: $color_one;
  .container {
    background-color: $color_two;
  }
}

Code in public/index.php

 SassCompiler::run("public/scss/", "public/css/");

Code in resources/views/hello.php

<!DOCTYPE html>

    <html>
    <head>
        <title>Laravel</title>
        <link rel="stylesheet" type="text/css" href="public/css/style.css">
    </head>
    <body>
    <div class="container">
        <div class="content">
            <div class="title">Laravel 5</div>
            This  is the master sidebar.
            <div class="container">
            </div>
        </div>
    </div>
    </body>
    </html>

Notice that I use a normal link to link css to HTML.

Hope someone can help.



via Chebli Mohamed

Laravel middleware one time authorization for route groups

I am designing some part of system in Laravel 5. It is expected to behavior as described below.

  1. User gets unique url. It could be provided in email, but that will not matter.
  2. He clicks it, and gets logged in with some temporary token (for a session lifetime), that gives him possibility to access all the urls in allowed route group, ex. account/*, but if he wants to reach other restricted urls, then he is asked to authorize with his username/password.
  3. If he is already authorized, token login makes no effect for him.

My question is about possibility to do something like that in Laravel out of box. I know there are some middleware services, but I'm not sure if default Guard behavior will not need to be changed to work as I expect. I used to work with Symfony before, and there it is solved by firewalls by default, so maybe also in Laravel there is prebuilt solution?



via Chebli Mohamed

php artisan clear-compiled failing

I cloned an existing laravel5 project from github repository. in my root using Mac terminal I ran composer install I got out put of dependency installation and at some point when output reached

> php artisan clear-compiled

I got the following error

Fatal error: Cannot redeclare createDirIfNotExist() (previously declared in /Users/applebook/projects/referral-system/Laravel5/laravel/config/constants.php:14) in /Users/applebook/projects/referral-system/Laravel5/laravel/config/constants.php on line 20

Script php artisan clear-compiled handling the pre-update-cmd event returned with an error

I'm stuck here since past few hours, nothing is working out. any command artisan , php artisan --version composer update is giving me same error.

Can anyone help me get through this ? Also if anybody suggest me a good tutorial setting up existing laravel5 project on mac os x ?



via Chebli Mohamed

Laravel 5 Authentification issue with "remember"

I have a phenomen that I do not understand about saving a session in Laravel 5.1

When my user connects by checking the "remember" box, I see the cookie "remember ..." which arrives on his computer. And when he does not check this box the cookie does not happen. See image below.

enter image description here

On the database side, the column "remember_token" is well fed.

When the same user closes his browser and relaunch the application : it works, he is well recognized.

The mechanical is working.

The problem is when he tries again later in a few hours, at the time the app recognizes no more.

My code is very classic, I do not think it's the origin of the issue.

Probably a config problem somewhere, but what?

Thanks in advance for your help.

dominique



via Chebli Mohamed

Get the value of REDIRECT using WITH in laravel

we are trying to get the value sent with the redirect method in blade template in laravel.

Here is how my return statement looks like:

public function movetotrash($id){

    $page = Pages::where('id', $id) -> first();
    $page -> active = 0;
    //$page -> save();
    //return redirect()->route('pages.index')->with('trash','Page Moved To Trash');
    return redirect('pages')->with('trash','Page Moved To Trash');
}

Now once its redirect to pages it creates are URL like this http://localhost:8888/laravelCRM/public/pages.

Then i want to print the message to user that "Page is moved to trash" with $trash variable. For which i used this :

@if(isset($trash) ))
                       <div class="alert alert-error">
                          {{ $trash }}<br><br>
                       </div>
                    @endif

What should i do to print the value?

Thank you! (in advance)



via Chebli Mohamed