jeudi 4 janvier 2018

Laravel 5.1 output AuthMiddleware Serverfireteam

BadMethodCallException in Macroable.php line 81: Method aliasMiddleware does not exist.

in Macroable.php line 81
at Router->__call('aliasMiddleware', array('PanelAuth', 'Serverfireteam\Panel\libs\AuthMiddleware')) in PanelServiceProvider.php line 36
at Router->aliasMiddleware('PanelAuth', 'Serverfireteam\Panel\libs\AuthMiddleware') in PanelServiceProvider.php line 36
at PanelServiceProvider->register() in Application.php line 531
at Application->register(object(PanelServiceProvider)) in ProviderRepository.php line 74
at ProviderRepository->load(array('Illuminate\Foundation\Providers\ArtisanServiceProvider', 'Illuminate\Auth\AuthServiceProvider', 'Illuminate\Broadcasting\BroadcastServiceProvider', 'Illuminate\Bus\BusServiceProvider', 'Illuminate\Cache\CacheServiceProvider', 'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider', 'Illuminate\Routing\ControllerServiceProvider', 'Illuminate\Cookie\CookieServiceProvider', 'Illuminate\Database\DatabaseServiceProvider', 'Illuminate\Encryption\EncryptionServiceProvider', 'Illuminate\Filesystem\FilesystemServiceProvider', 'Illuminate\Foundation\Providers\FoundationServiceProvider', 'Illuminate\Hashing\HashServiceProvider', 'Illuminate\Mail\MailServiceProvider', 'Illuminate\Pagination\PaginationServiceProvider', 'Illuminate\Pipeline\PipelineServiceProvider', 'Illuminate\Queue\QueueServiceProvider', 'Illuminate\Redis\RedisServiceProvider', 'Illuminate\Auth\Passwords\PasswordResetServiceProvider', 'Illuminate\Session\SessionServiceProvider', 'Illuminate\Translation\TranslationServiceProvider', 'Illuminate\Validation\ValidationServiceProvider', 'Illuminate\View\ViewServiceProvider', 'Intervention\Image\ImageServiceProvider', 'Collective\Html\HtmlServiceProvider', 'Barryvdh\Debugbar\ServiceProvider', 'Baum\Providers\BaumServiceProvider', 'Barryvdh\TranslationManager\ManagerServiceProvider', 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider', 'Greggilbert\Recaptcha\RecaptchaServiceProvider', 'Serverfireteam\Panel\PanelServiceProvider', 'pulsar\Providers\AppServiceProvider', 'pulsar\Providers\HelperServiceProvider', 'pulsar\Providers\AuthServiceProvider', 'pulsar\Providers\EventServiceProvider', 'pulsar\Providers\RouteServiceProvider')) in Application.php line 507
at Application->registerConfiguredProviders() in RegisterProviders.php line 17
at RegisterProviders->bootstrap(object(Application)) in Application.php line 203
at Application->bootstrapWith(array('Illuminate\Foundation\Bootstrap\DetectEnvironment', 'Illuminate\Foundation\Bootstrap\LoadConfiguration', 'Illuminate\Foundation\Bootstrap\ConfigureLogging', 'Illuminate\Foundation\Bootstrap\HandleExceptions', 'Illuminate\Foundation\Bootstrap\RegisterFacades', 'Illuminate\Foundation\Bootstrap\RegisterProviders', 'Illuminate\Foundation\Bootstrap\BootProviders')) in Kernel.php line 222
at Kernel->bootstrap() in Kernel.php line 117
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 54

Routes

<?php

get('/', 'FrontendController@index');

get('/bayi-basvuru-formu', function (){
    return view('frontend.bayi-basvuru-formu');
});

  Route::post('contact_store', 
  ['as' => 'contact_store', 'uses' => 'FrontendController@store']);
include 'adminRoutes.php';



via Chebli Mohamed

mercredi 3 janvier 2018

Laravel web application website url case sensitivity Upper case lower case

I have a web application build in php Laravel Framework version 5.1.19. It is running on plesk server, I am having problem with website url case sensitivity. Before the website was working in lower case url but know it does not work. I have to put the path in uppercase for eg: http://ift.tt/2E01MJV it was working before in this format but now it is not working but when I write http://ift.tt/2EPuSg8 it will work. Note Url used is just for demonstration. What should I do ?



via Chebli Mohamed

mardi 2 janvier 2018

Multi storage paths

I have server with 2 hdd. I want to use one for all media files, which are on storage/app/media for current media files and other for all files before 2018.

How can I switch storage path depends on query I make.

All media are saved on media table. I can make changes on table if needed.



via Chebli Mohamed

Laravel 5.1 How to sort collection using lists() method

I have two questions/help to fix here:

  1. How to reduce redundancy in this line of code $this->all()->lists('name', 'id')->all()
  2. How to call mutator by using orderBy method.

helper.php

if (! function_exists('withEmpty')) {

    function withEmpty($selectList, $emptyLabel = '')
    {
        return array('' => $emptyLabel) + $selectList;
    }
}

Agent.php (model)

public function getNameAttribute($value){
    return $this->lname.', '.$this->fname.' '.$this->mname;
  }

public function listAgents($emptyLabel = '--Select Agent--'){

    return withEmpty($this->all()->lists('name', 'id')->all(), $emptyLabel);


  }



via Chebli Mohamed

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