vendredi 1 janvier 2016

How to detect all the text which has an @ sign in a paragraph in php

In my current php project, I'm sending some special texts attached with an @ sign in a paragraph to the back end. I need to detect all the words which has an @ sign and take them as an array. I was trying with the following regex, but its not working, can anyone help me to fix this

$text = "my text has some @signs and @names";    
preg_match_all('/(?<!\w)@\w+/', $text, $matches);
print_r($matches);



via Chebli Mohamed

Laravel 5.1 defer service provider until another is loaded

I'm using the FormBuilder in Laravel 5.1. The HtmlServiceProvider states the Html and Form facades should defer loading until they are actually needed, which is fine.

However, I have created a FormServiceProvider which registers several macros that I will use in my views. This provider doesn't run any bindings, it simply records a few macros within the FormBuilder class.

However, by storing these macros using the boot method on my own service provider, it's loading the Form binding instantly (making the deferred loading pointless).

Question

Is there any way to defer the boot method in one service provider until another service provider has binded facades?

OR, is there a way to listen for specific binding (or aliasing) events, then manually run a service provider?



via Chebli Mohamed

Route Issue in Anchor Link in Laravel 5.2

I have route defined in the Route.php file like below

Route::get('/SubCategories-List/{categoryID}', 'Skills\Category_Controller@SubCategories');

Below is the code done in Blade for showing list of records.

@foreach($Categories as $Category)
    <tr class="odd pointer">
        <td class=" last">
            <a href="{{Route('SubCategories-List', [$Category->CategoryID])}}">
                 Sub Categories
            </a>
        </td>
    </tr>
@endforeach

I am getting the following error when action method calls the blade

Route [SubCategories-List] not defined.

Am I missing something ?



via Chebli Mohamed

Laravel 5.1 auth logs out after refresh

I'm working with Laravel for the first time. My auth user logs out automatically after i go to another route or if i refresh the page, and i dont understand why, please help me.

This is my log in code:

public function ini_ses(Request $datos)
{
    //Inicia sesion
    Session::put('ses_correo', Input::get('email'));

    $correo = $datos->input('email');
    $password= $datos->input('password');

    if(Auth::attempt(['correo_elec'=>$correo, 'password'=>$password]))
    {
        $_session['correo']=$correo;
        $_session['contra']=$password;

        if(Auth::user()->tipo==0)
        {
            return view('cliente');
        }
        elseif(Auth::user()->tipo==1)
        {
            return view('veterinario');
        }
        elseif(Auth::user()->tipo==2)
        {
            echo("Admin");
        }
    }
    else
    {
        var_dump($correo, $password);
    }

}

If you know how to fix it, i aprecciate your help.



via Chebli Mohamed

Call to undefined method Illuminate\Support\Facades\Validator::resolver()

What is it about ?

I am using Laravel 5.2 and update the composer by running the following command

composer require felixkiss/uniquewith-validator:2.*

I did this because I am trying to implement Multiple column Unique Validation. I mean Composite Key Validation.

I am following the instructions as mentioned here

What's the issue ?

When Laravel runs the below line.

$v = \Validator::make($request->all(), [
    'SubCategory' => 'required|max:25|min:5|unique_with:tblsubcategory,CategoryID',
    'CategoryID' => 'required',
]);

I get this error.

Call to undefined method Illuminate\Support\Facades\Validator::resolver()

Important

This was working fine in Laravel 5.1



via Chebli Mohamed

How to move my controllers into a seperate package folder in Laravel 5.2?

I build a small app using laravel 5.2. I put all of my files into a folder called Surveys located at App/Modules/Surveys. "No worries, I am planning to move the Modules out of the App folder, I just need to get the controller to work"

Currently my controller is located on App/Http/Controllers/SurveysController

I want to move my controller folder so it is located on App/Modules/Surveys/Controllers/Frontend/SurveysController

How would I tell laravel to resolve the controller out of this path App/Modules/Surveys/Controllers/Frontend/ instead of App/Http/Controllers?

I tried to do this into a service provider but it is still not working

<?php

namespace App\Modules\Surveys\Providers;

use Illuminate\Support\ServiceProvider;

class PackageServiceProvider extends ServiceProvider
{

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {

        if (! $this->app->routesAreCached()) {
            require __DIR__.'/../routes.php';
        }

    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {

        $this->app->make('Modules\Surveys\Controllers\Frontend\SurveyController');
    }

}

What should I do to make the routes point to the correct controller?

Just for clarity my Application instructor starts at the App

App/Https/Controllers App/Modules/Surveys



via Chebli Mohamed

Laravel 5.1 - Can't access Auth:user()->data from my controllers

I've been having a little trouble with Auth data in Laravel 5.1 I want to get the id of the Logged user and It works if I use it in a View, lets say:

<?php echo Auth::user()->id;?>

But if I try to access to it in a Controller it dowsnt work, and I get this error:

ErrorException in Con_Mascota.php line 101:
Trying to get property of non-object

In line 101 i've:

$cod_usu=$request->user()->cod_usu;

I changed that from $cod_usu=Auth::user()->cod_usu; cause that didnt work either.

Im also including it in the Controller:

use Auth;

Any help is much appreciated :)



via Chebli Mohamed