lundi 25 décembre 2017

laravel5.4 I can't get login , when i try to login it always redirect to same login page

Web.php

Route::get('/' , ['as' => '/' , 'uses'=> 'loginController@getlogin']);
Route::post('/login', ['as' => 'login', 'uses'=> 'loginController@postlogin']);

Route::group(['middleware' =>['authen']],function (){
Route::get('/logout' ,['as'=>'logout', 'uses'=> 'loginController@getLogout']);
Route::get('/dashboard',['as'=>'dashboard', 'uses'=> 'dashboardController@dashboard']);});

dashboardController

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class dashboardController extends Controller
{
   public function __construct(){
    $this->middleware('web');
   }
   public function dashboard(){
    return view('layouts.master');
   }
}

loginController

<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Auth;
class LoginController extends Controller{
     use AuthenticatesUsers;
     protected $username = 'username';
     protected $redirectTo = '/dashboard';
     protected $guard = 'web';

     public function getLogin(){
        if(Auth::guard('web')->check()){
           return redirect()->route('dashboard');
        }
        return view('login');
     }

     public function postLogin(Request $request){
         $auth = Auth::guard('web')->attempt([
            'username' => $request->username,
            'password' => $request->password,
            'active' => 1
          ]);

          if($auth){
             return redirect()->route('dashboard');
           }
           return redirect()->route('/');
     }

     public function getLogout(){
        Auth::guard('web')->logout();
        return redirect()->route('/');
     }
}

Authen.php

<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class Authen
{
public function handle($request, Closure $next ,$guard ='web'){
    if (!Auth::guard($guard)->check()){
      return redirect()->route('/');   
    }
      return $next($request);
    }
}

CheckRole

<?php
namespace App\Http\Middleware;
use Closure;
class CheckRole
{
/**
 * Handle an incoming request.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  \Closure  $next
 * @return mixed
 */
     public function handle($request, Closure $next){
         $roles = $this->getRequiredRoleForRoute($request->route());
         if($request->user()->hasRole($roles) || !$roles){
            return $next($request);
         }
          return redirect()->route('noPermission');
      }

      private function getRequiredRoleForRoute($route){
          $actions = $route->getAction();
          return isset($actions['roles']) ? $actions['roles'] : null;     
      }
}

when i try to login it redirect to the same page i.e login page , i spent lots of hour to solve this problem but i can't please someone help me . i want to redirect dashboard through login page . but it is not happen . there is no error shown and i cant go on dashboard page too.Please help me to solve this problem. Thanks so much.



via Chebli Mohamed

dimanche 24 décembre 2017

sending error message laravel required inputs

so i wanted to make validation to my register form so i made all my inputs required so i can test my validation that it works or not, so this is what i used in my controller

$Message = [
        'required' => 'This input is required',
    ];
    $validator = Validator::make($request->all(), [
        'name' => 'required',
        'email' => 'required',
        'password' => 'required',
        'UserName' => 'required',
        'Phone' => 'required',
        'SSN' => 'required',
        'SDT' => 'required',
        'Country' => 'required',
        'InsuranceAmount' => 'required',
        'City' => 'required',
        'Location' => 'required'
    ], $Message);

    if ($validator->fails()) {


        return redirect('/admin/users/create')
            ->withErrors($validator)
            ->withInput();
    }

    $user = new User;
    $user->name = Input::get('name');
    $user->email = Input::get('email');
    $user->password = bcrypt(Input::get('password'));
    $user->UserName = input::get('UserName');
    $user->Phone = input::get('Phone');
    $user->SSN = input::get('SSN');
    $user->SDT = input::get('SDT');
    $user->Country = input::get('Country');
    $user->City = input::get('City');
    $user->Location = input::get('Location');
    $user->save();
    return Redirect::to('/admin/users')->with('message', 'User Created');

Now if theres no errors it works fine and redirect to user list, but if a input is empty it will just redirect to the creation page whict is what i wanted but the problem is it won't send the error message with the redirect i tried dd the validator and it has all the messages fine heres my view

<form class="form-horizontal" role="form" method="POST" action="">
                    {!! csrf_field() !!}

                    <div class="form-group">
                        <label class="col-md-4 control-label">الاسم</label>

                        <div class="col-md-6">
                            <input type="text" class="form-control" name="name" value="">

                            @if ($errors->has('name'))
                                <span class="help-block">
                                    <strong></strong>
                                </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group ">
                        <label class="col-md-4 control-label">اسم المستخدم</label>

                        <div class="col-md-6">
                            <input type="text" class="form-control" name="UserName" value="">
                            @if ($errors->has('UserName'))
                                <span class="help-block">
                                    <strong></strong>
                                </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group ">
                        <label class="col-md-4 control-label">رقم الجوال</label>

                        <div class="col-md-6">
                            <input type="text" class="form-control" name="Phone" value="">
                            @if ($errors->has('Phone'))
                                <span class="help-block">
                                    <strong></strong>
                                </span>
                            @endif

                        </div>
                    </div>

                    <div class="form-group ">
                        <label class="col-md-4 control-label">الرقم الوطني</label>

                        <div class="col-md-6">
                            <input type="text" class="form-control" name="SSN" value="">
                            @if ($errors->has('SSN'))
                                <span class="help-block">
                                    <strong></strong>
                                </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group ">
                        <label class="col-md-4 control-label">نوع الوثيقة</label>

                        <div class="col-md-6">
                            <input type="text" class="form-control" name="SDT" value="">
                            @if ($errors->has('SDT'))
                                <span class="help-block">
                                    <strong></strong>
                                </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group ">
                        <label class="col-md-4 control-label">الدولة</label>

                        <div class="col-md-6">
                            <select class="form-control" name="Country">

                                <option>الاردن</option>
                            </select>

                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-4 control-label">المدينة</label>

                        <div class="col-md-6">
                          <select class="form-control" name="City" >
                              <option>عمان</option>
                          </select>

                        </div>
                    </div>

                    <div class="form-group ">
                        <label class="col-md-4 control-label">اسم الشارع</label>

                        <div class="col-md-6">
                            <input type="text" class="form-control" name="Location" value="">
                            @if ($errors->has('Location'))
                                <span class="help-block">
                                    <strong></strong>
                                </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group ltr-input">
                        <label class="col-md-4 control-label">البريد الإلكتروني</label>

                        <div class="col-md-6">
                            <input type="email" class="form-control" name="email" value="">

                            @if ($errors->has('email'))
                                <span class="help-block">
                                    <strong></strong>
                                </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group ltr-input">
                        <label class="col-md-4 control-label">كلمة المرور</label>

                        <div class="col-md-6">
                            <input type="password" class="form-control" name="password">

                            @if ($errors->has('password'))
                                <span class="help-block">
                                    <strong></strong>
                                </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group ltr-input">
                        <label class="col-md-4 control-label">تأكيد كلمة المرور</label>

                        <div class="col-md-6">
                            <input type="password" class="form-control" name="password_confirmation">

                            @if ($errors->has('password_confirmation'))
                                <span class="help-block">
                                    <strong></strong>
                                </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-md-6 col-md-offset-4">
                            <button type="submit" class="btn btn-primary pull-right">
                                <i class="fa fa-btn fa-user"></i> تسجيل
                            </button>
                        </div>
                    </div>
                </form>

and btw this is laravel 5.1



via Chebli Mohamed

samedi 23 décembre 2017

Laravel Has anyone been able to use GMAIL API, OUTLOOK API and Yahoo Mail API together?

I am looking to build an email reading and message sending app with Laravel 5.1. I don't want to use IMAP or POP3. Instead, I would like to use GMAIL API, OUTLOOK API and Yahoo Mail API for both logins using Oauth and accessing user email accounts. Is there a Laravel module or a service that can do that?



via Chebli Mohamed

vendredi 22 décembre 2017

Need help in optimising Laravel Mysql query

Can anyone help me out in explaining this below query in detail? This is part of my project which i got to debug. i need help to understand it and optimise this.

$query = seller::selectRaw("seller.name, seller.group_id,seller.group_id_string, seller.pay,( 
    SELECT SUM( IF( t.retail_cost >0
    AND t.submitted_group_plan >1, 1 , -1 ) ) AS trans_number
    FROM money AS t
    JOIN  `seller` AS d ON  `t`.`submitted_group_plan` =  `d`.`group_id` 
    WHERE 
    (
        (
        t.`claim_date_and_time` >=  '01-01-2015'
        AND t.`claim_date_and_time` <=  '01-01-2016'
        AND t.commissionable =  'Y'
        AND t.`submitted_group_plan` = d.group_id
        )
        OR 
        (
            (t.commissionable IS NULL)
            AND 
            (t.claim_type_code IS NULL)
            AND
            (t.claim_date_and_time IS NULL)
        )
    )
    AND d.id = seller.id)
    as trans_number");  

MYSQL VERSION OF ABOVE QUERY:

SELECT seller.name,
       seller.group_id,
       seller.group_id_string,
       seller.pay,

  (SELECT SUM(IF(t.retail_cost >0
                 AND t.submitted_group_plan >1, 1, -1)) AS trans_number
   FROM money AS t
   JOIN `seller` AS d ON `t`.`submitted_group_plan` = `d`.`group_id`
   WHERE ((t.`claim_date_and_time` >= '01-01-2015'
           AND t.`claim_date_and_time` <= '01-01-2016'
           AND t.commissionable = 'Y'
           AND t.`submitted_group_plan` = d.group_id)
          OR ((t.commissionable IS NULL)
              AND (t.claim_type_code IS NULL)
              AND (t.claim_date_and_time IS NULL)))
     AND d.id = seller.id) AS trans_number
FROM `seller`



via Chebli Mohamed

mercredi 20 décembre 2017

How to calculate between hours from current date to pickupdate in Laravel

How to calculate between hours from current date to pickupdate. I have pickup date and pickup Time from Input. below function returns wrong value.

$bookingtime=strtotime($request->input('pickupdate_submit')." ".$request->input('pickuptime_submit') );

        $curentdate=date('Y-m-d HH:i');
        $curenttime=strtotime($curentdate);

        $betweenhours = abs($bookingtime - $curenttime) / 3600;



via Chebli Mohamed

lundi 18 décembre 2017

Change Login Table in Laravel 5.5

I have two table one is "clUser" in which i am storing email id, another table name "clLogin" in which i am storing Password. How to change laravel default login with these two table.



via Chebli Mohamed

mardi 12 décembre 2017

Update form only if there is some change in the input fields

How to determine in update() method of a controller in a laravel project if there is any change in the input? I need to update form only if there is any change in the input fields.



via Chebli Mohamed

lundi 11 décembre 2017

Laravel 5.1 I cant update model $user

I have this function where I want to update user background image so I write:

public function updateBg(Request $request)
    {
        $user = Auth::user();
        $this->validate($request, [
            'background' => 'image|max:10000',
            // validate also other fields here
        ]);
        // checking file is valid.
        if (!$request->file('background')->isValid()) return redirect()->back()->withErrors(["background" => "File is corrupt"]);

        // file is valid
        $destinationPath = public_path().'/images/Custaccounts/'.$user->id; // upload path
        $extension = $request->file('background')->getClientOriginalExtension(); // getting image extension
        $ran = str_random(5);
        $photo  = $ran.'.'.$extension;

        $request->file('background')->move($destinationPath, $photo); // uploading file to given path

        $bg = $user->id.'/'.$photo;
dd($bg);
        $user->update(['background' => $bg]);

        return Redirect::back();

            }

this line wont work: $user->update(['background' => $bg]); dd($bg) give me right string and image is uploaded just I cant update my 'background; field ...

also when I write:

    $user->update(['background' => $bg, 'name'=>'John']);

name is updated but background not... at user model background field is fillable of cource



via Chebli Mohamed

dimanche 10 décembre 2017

How to access passed data inside a redirect route from blade template

I have a method that redirect to a route like this with a data passed inside it:

return redirect('vendors')->with('vendor',$allvendors);

and i want to access the data that i passed from a blade template that the redirect is pointing to, so i did something like this:

@foreach($vendor as $vendors)

but i am getting this error:

Undefined variable: vendor (View: /opt/lampp/htdocs/easyhire-web/resources/views/vendor/vendors.blade.php)

I rely don't know what i am doing wrong, but when i return a view with that same data, it will work but if i change it to redirect, it will give error. any help out there?



via Chebli Mohamed

jeudi 7 décembre 2017

Laravel 5: Store artisan console table output in a variable

In Laravel 5 console commands, you can output a table like so:

$this->table($headers, $tableData);

This is described here: http://ift.tt/2j4EAW2

However this outputs it straight to the console.

How can I store it in a variable without sending the data to the console.



via Chebli Mohamed