samedi 31 décembre 2016

How to shorten a url in .htaccess file

I have a wordpress website with the integration of a laravel5.1 app. I use a couple views from the laravel app. How can I shorten the the following url

http://ift.tt/2hWLOWi

I would like to remove /larave-app/public/ from the url so that when they click on the link the url shows as

http://ift.tt/2hF6K83

I am not sure if I need to update the .htaccess file in the laravel-app/public folder or the .htaccess file in wordpress or in both files. Thanks



via Chebli Mohamed

vendredi 30 décembre 2016

Laravel 5.1 login register display custom error messages

I was start working with basic Auth in Laravel, described here: http://ift.tt/2hDeA2h

Everything works properly, when I enter right credentials I will authorised, and redirected, thats great but, when I enter bad credentials, nothing happens, just refresh the form...

I need to display custom error messages like "Bad credentials", "Please fill all inputs" for register ... "Email already registred" etc.

But I do not know, how can I do that.

Which method, or which file to edit to do that.

My login form looks simple from docs:

<form method="POST" action="login">
    {!! csrf_field() !!}

    <div>
        Email
        <input type="email" name="email" value="">
    </div>

    <div>
        Password
        <input type="password" name="password" id="password">
    </div>

    <div>
        <input type="checkbox" name="remember"> Remember Me
    </div>

    <div>
        <button type="submit">Login</button>
    </div>
</form>

Register form too:

<form method="POST" action="register">
    {!! csrf_field() !!}

    <div>
        Email
        <input type="email" name="email" value="">
    </div>

    <div>
        Password
        <input type="password" name="password">
    </div>

    <div>
        Confirm Password
        <input type="password" name="password_confirmation">
    </div>

    <div>
        <button type="submit">Register</button>
    </div>
</form>

And AuthController like this:

 use AuthenticatesAndRegistersUsers, ThrottlesLogins;
    private $redirectTo = '/testing';
    /**
     * Create a new authentication controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest', ['except' => 'getLogout']);
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|confirmed|min:6',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
        return User::create([
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
    }
}

Thank you very much, have a great time!



via Chebli Mohamed

Error in larabel 5.1. method save

Error while trying to save logs in larabel 5.1. The code and screenshot of the error shown below. I do not know how to solve them if I appeal to you, I look forward to your help. Thanks

 <?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Grupo;

use App\Http\Requests;

use App\Http\Controllers\Controller;


class ControllerGrupos extends Controller
{


    public function agregar_Grupo(Requests $request)
    {
        $nom = $request->get('name');

        $des   = $request->get('descrition');
        $grupo = new Grupo();


        $grupo->nombre      = $nom;
        $grupo->descripcion = $des;
        $grupo->save();

        return view('grupos.agregar_grupo');
    }

}

this error this error image



via Chebli Mohamed

Laravel 5.1 route not defined redirect

need to ask about error, when I tried to redirect my logout

This is UserController:

    public function logout()
{

    Auth::logout();
    return redirect()->route('auth/login');
}

This is my routes:

Route::get('/', function () {
    return view('welcome');
});
// Authentication routes...
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');

// Registration routes...
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');

Route::get('testing', 'UserController@test');
Route::get('logout', 'UserController@logout');

I think, taht everything is ok on routes and I defined login properly (like a Laravel documentation)

but it still take this error:

InvalidArgumentException in UrlGenerator.php line 306:
Route [auth/login] not defined.

Can you please what is wrong? Did I make any mistake?

Thanks a lot, have a nice day!



via Chebli Mohamed

jeudi 29 décembre 2016

Send Validator Instance key along with keys given in rule method

Issue

Validator Instance is not sending the InvalidAttempts key along with other keys. Instead, it send when the validation is passed for all keys given in rule method.

My request class is like below

class RegisterRequest extends Request
{
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'Password'      => 'required',
            'EmailAddress'  => 'required',
            'UserName'      => 'required'

        ];
    }    
}

I am trying to add a key which will inform user that that are left with this many attempts and for that I am writing below code and my final request class becomes like below.

class RegisterRequest extends Request
{
    use ThrottlesLogins;

    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'Password'     => 'required',
            'EmailAddress' => 'required',
            'UserName'     => 'required'            
        ];
    }

    protected function getValidatorInstance()
    {
        $instance = parent::getValidatorInstance();
        $instance->after(function ($validator) {
            $this->CheckTotalAttempts($validator);
        });
        return $instance;
    }

    public function CheckTotalAttempts($validator)
    {
        if ($this->hasTooManyRegisterAttempts($this)) {
            $validator->errors()->add('InvalidAttempts', $this->TotalAttemptsLeft($this) 
                                     . " attempts left.");
        }
    }
}



via Chebli Mohamed

Laravel/Composer: adding seeds programmatically

Currently I'm trying to develope a package update system with the following workflow. I'm creating a package (.zip) with the following files:

  • migrations (folder)
    • migrationClass
    • ..
  • seeds
    • seedfile
    • ..
  • package.xml
  • UpdateInstructionSeeder.php

As a administrator I can upload this package in my admin control panel to update my database.

backend workflow:

  1. get data from package.xml (get available seeds and migrations)
  2. check if a migration/seeding is needed
  3. migrate (works fine)
  4. seed (fails)

So, as you can see I have some trouble with my seeding.

At first I tried to move (with Storage::move()) my seeds from the package seed folder to the database/seed/ directory. I tried to seed it with Artisan::call('db:seed','--class']); but a Class MyClass does not exist error appeared. I guessed that there are some problems with my autoloader, so I've tried to dump it with system('composer dump-autoload', $test);. The output of $test was 1 but the autoload_classmap wasn't updated.

Now I've added a UpdateInstructionSeeder.php which is available in my framework by default to fix the autoloader problem. After uploading my package, I'm using now Storage::get() and Storage::put() to update this with my needed seeds.

Now I'm adding seeds with Artisan::call('make:seeder', ['name' => $className]); ($className is the name of my seeds from the package) and update them with Storage::get() and Storage::put(), too.

Now I'm calling my seeder with Artisan::call('db:seed','--class' => ']);. Result: Class MyClass does not exist

Content:

package UpdateInstructionSeeder

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;

class UpdateInstructionSeeder extends Seeder
{
   /**
    * Run the database seeds.
    *
    * @return void
    */
   public function run()
   {
       Model::unguard();

       $this->call(DemoTableSeeder::class);

       Model::reguard();
   }
}

package DemoTableSeeder

<?php

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;

class DemoTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Model::unguard();

        DB::table('demos')->insert([
            [
                'demoInt' => 1,
                'demoString' => "a"
            ],
            [
                'demoInt' => 11,
                'demoString' => "aa"
            ],
        ]);

        Model::reguard();
    }
}

I wasted now a lot of hours and I have absolutely no idea to solve this problem programatically.



via Chebli Mohamed

Laravel5.1 can you passed an incremental variable in to a sub-view

I am trying to pass an incremental variable to a blade template subview to add a number to a class name.

@for($x=1; $x < 4; $x++)
            <div class="col-md-3">
                {!! Form::label('amenIcon'.$x,'Amenity Icon '.$x) !!}
                {!! Form::select('amenIcon'.$x,
                 [null =>'Choose Icon'] + $iconDirectory)
                    !!}
            </div>
                @include('portal._iconModals')
            @endfor

The sub-view portal._iconModals

div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">Choose Icons</h4>
        </div>
        <div class="modal-body">
            <div class="row">
                <div class="col-md-12" id="bsnImage">
                    @foreach($brandSocialIcons as $bIcons)
                        <a href="javascript:void(0);" class="iconChoice"><img src="../../../../storage/icons/"></a>
                    @endforeach
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
    </div>
</div>

I would like to increment the class name iconChoice because the I have 3 select fields with options that use the same subview but because of the class name when I choose one of the images with the class of iconChoice it chooses it for all 3 select list instead.

Here is the js code $( "#amenIcon1" ).click(function() {

     $('.iconChoice').click(function() {
         var $thumb = $(this);
         console.log($thumb);

         var icon1 = $thumb.find('img').attr('src');
         displayIcon1(icon1)
     });
     function displayIcon1(icon1) {
         $("#icon1Thumb").attr("src",icon1);
     }
 });

Might not be the best explanation but I will to elaborate more if need be. Thanks



via Chebli Mohamed