dimanche 21 août 2016

Laravel login not working properly

I tried to create a basic login, but somehow it did not work correctly.

My Form looks like this:

            <form role="form" method="POST" action="/auth/login" class="form col-md-12 center-block">
                {!! csrf_field() !!}

                <div class="form-group">
                    <input type="email" class="form-control input-lg" name="email" value="" placeholder="Email">
                </div>

                <div class="form-group">
                    <input type="password" class="form-control input-lg" name="password" placeholder="Passwort">
                </div>

                    <div class="form-group">
                        <button type="submit" class="btn btn-primary btn-lg btn-block">Login</button>
                    </div>
            </form>

My Login routes look like this:

# Login, Logout
Route::get('auth/login', ['as' => 'newSession', 'uses' => 'Auth\AuthController@getLogin']);
Route::post('auth/login', ['as' => 'createSession', 'uses' => 'Auth\AuthController@postLogin']);
Route::get('auth/logout', ['as' => 'destroySession', 'uses' => 'Auth\AuthController@getLogout']);

My login form shows correctly at this url :

http://localhost/myApp/public/

When I press login I get an error:

Object not found 404

Url looks like this then

http://localhost/auth/login

I want to redirect the user to product/home (folder product inside the product folder home.blade.php), after the user is logged in.



via Chebli Mohamed

Laravel 5.1 and sendgrid store attachments in inbound parse

I want to be able to receive e-mails in my own application trough SendGrid. Now, receiving e-mails work, except the fact that I can't get the attachments stored bu user etc...

So I want to store the attachments on my server to let a user see them as attachemnt in the e-mail.

I don't know how I should do this, so could anyone help me out?

I currently store the e-mails with this code:

public function ReceiveMail(Request $request)
    {
      DB::table('email')->insert([
          'headers' => $request->get('headers'),
          'html' => $request->get('html'),
          'from' => $request->get('from'),
          'sender_ip' => $request->get('sender_ip'),
          'to' => $request->get('to'),
          'cc' => $request->get('cc'),
          'subject' => $request->get('subject'),
          'dkim' => $request->get('dkim'),
          'spf' => $request->get('spf'),
          'envelope' => $request->get('envelope'),
          'charsets' => $request->get('charsets'),
          'spam_score' => $request->get('spam_score'),
          'spam_report' => $request->get('spam_report'),
          'attachments' => $request->get('attachments'),
          'attachment-info' => $request->get('attachment-info'),
          'attachmentX' => $request->get('attachmentX')
      ]);

      PushBullet::all()->note('E-mail', 'Nieuwe e-mail van '.Self::get_string_between($request->get('from'), '<', '>').' aan '.Self::get_string_between($request->get('to'), '<', '>').'.');

      return 'ok';
    }

Any suggestions to improve the code or to change things to make receiving e-mails better and more secure are also welcome!



via Chebli Mohamed

Retrieve all users based on where condition of relationship

I'm trying to build a search system for my users.

The first part of this was easy as all the information I was searching was in the same table.

The second part involves searching for users based upon a provided IP address. For this I am using:

$users = User::with(array('login' => function($q){
                $q->where('ip_address', Input::get('ipaddress'));
            }))->paginate(10);

However this is returning all users, rather than just those that meet the IP address requirements. Where am I going wrong? Or is there an easier way to do this?



via Chebli Mohamed

samedi 20 août 2016

Search not working in laravel 5.1

I am currently doing a project. In this project I cant do my search form working.My search button not showing any value. It just returned an empty page. Please Help Me. My Route is

Route::get('/search', array('as' =>'search' ,'uses' => 'UserController@search'));

My Blade Template is

<header id="header">
    <div class="top-bar">
        <div class="container">
            <div class="row">
                <div class="col-sm-12 col-xs-12">
                   <div class="social">
                        <ul class="social-share">
                            <li><a href="#"><i class="fa fa-google-plus"></i></a></li>
                            <li><a href="#"><i class="fa fa-facebook"></i></a></li>
                            <li><a href="#"><i class="fa fa-twitter"></i></a></li>
                            <li><a href="#"><i class="fa fa-skype"></i></a></li>
                        </ul>
                        <div class="search">
                            {!! Form::open(['route' => 'search', 'method'=> 'GET']) !!}

                                <input type="text" class="search-form" name="search" autocomplete="off" placeholder="Search">

                                    <i class="fa fa-search"></i>

                            {!! Form::close() !!}
                            </div>
                       </div>
                   </div>
                </div>
            </div>
        </div><!--/.container-->
    </div><!--/.top-bar-->

    <nav class="navbar navbar-inverse" role="banner">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="{!! URL::route('home') !!}">{!! Html::image('images/logo.png','logo') !!}</a>
            </div>

            <div class="collapse navbar-collapse navbar-right">
                <ul class="nav navbar-nav">
                    <li <?php if($active == 'home') {echo 'class="active"';} ?>><a href="{!! URL::route('home') !!}">Home</a></li>

                    <li <?php if($active == 'about_us') {echo 'class="active"';} ?>><a href="{!! URL::route('about_us') !!}">About Us</a></li>

                    <li <?php if($active == 'hospital') {echo 'class="active"';} ?> class="dropdown" >
                        <a  href="#" class="dropdown-toggle" data-toggle="dropdown">Hospitals <i class="fa fa-angle-down"></i></a>
                        <ul class="dropdown-menu">
                            @foreach($divisions as $division)

                                <li><a href="{!! URL::route('district', $division['id']) !!}"></a></li>

                            @endforeach 

                        </ul>
                    </li>

                    <li <?php if($active == 'doctor') {echo 'class="active"';} ?> class="dropdown" >
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Doctors <i class="fa fa-angle-down"></i></a>
                        <ul class="dropdown-menu">

                        @foreach($divisions as $division)
                                <li><a href="{!! URL::route('districts',$division['id']) !!}"></a></li>

                            @endforeach 

                        </ul>
                    </li>

                    <li <?php if($active == 'contact') {echo 'class="active"';} ?>><a href="{!! URL::route('contact') !!}">Contact Us</a></li>

                    <li <?php if($active == 'login') {echo 'class="active"';} ?>><a href="{!! URL::route('login') !!}">Login</a></li> 

                    <li <?php if($active == 'register') {echo 'class="active"';} ?>><a href="{!! URL::route('register') !!}">Sign Up</a></li>                           
                </ul>
            </div>
        </div><!--/.container-->
    </nav><!--/nav-->

</header><!--/header-->

My Controller is

public function search(Request $req)
    {

        $divisions = Division::all();
        $doctors = Doctor::orderBy('name');
        $name = $req->input('name');
        if(!empty($name)) {
             $doctors->where('name', 'LIKE', '%' . $name . '%');
        }
        $doctors=$doctors->paginate(1);
       return view('users.index')
                   ->with('divisions',$divisions)
                   ->with('doctors',$doctors);

    }



via Chebli Mohamed

Input::hasFile() not working

I am trying to check if the image that i am trying to upload is getthing processed, but when i try to use de Input::hasFile('upimg') to check it out it doesnt do anything. This is my form:

{!! Form::open(array('route' => array('uploadimage'), 'method' => 'POST')) !!}
                    {!! csrf_field() !!}
                    <div class="form-group">
                        {!! Form::label('newimg', 'Choose Image to upload:', ['class' => 'control-label']) !!}
                        {!! Form::file('upimg', null) !!}
                    </div>
                    <div class="form-group">
                        {!! Form::label('directory', 'Choose directory:', ['class' => 'control-label']) !!}
                        {!! Form::select('newimage', [ '' => 'none'] + $imagesdir , '', ['class' => 'form-control']) !!}
                    </div>

                    {!! Form::submit('Upload', ['class' => 'btn btn-primary']) !!}

                    {!! Form::close() !!}

And this is the code i am using to check the file:

public function doUpload()
{
   if (Input::hasFile('upimg')){
      echo 'uploaded';
   }; 
}

As you can see i am trying to check:

{!! Form::file('upimg', null) !!}

If i am not wrong its suppose to give mi back the echo but nothing happens. Why is this not working? what am i doing wrong?



via Chebli Mohamed

Dynamic redirect after not working in Laravel 5.1

I've followed the instructions here to make a login page. It's working; however I'm having trouble making the redirect dynamic. What I mean is that, I want to redirect the user to different URLs, based on their role (custom models that I've already defined).

Here's my AuthController (I've removed boilerplate):

 use AuthenticatesAndRegistersUsers, ThrottlesLogins;
 private $redirectTo = '/test';

 public function __construct()
 {
     $this->middleware('guest', ['except' => 'getLogout']);

     $this->redirectTo = '/dashboard';
     $user = \Auth::user();
     if ( ($user->admin() ) {
     // an admin
         $this->redirectTo = '/admin';
     } else {
     // it's a client
         $this->redirectTo = '/client/dashboard';
     }
 }

 protected function validator(array $data)
 {
     return Validator::make($data, [
         'name' => 'required|max:255',
         'email' => 'required|email|max:255|unique:users',
         'password' => 'required|confirmed|min:6',
     ]);
 }

However, it still redirects everyone to /home. I've dd($this->redirectTo) and it shows the expected value.

How do I dynamically set the redirect path after a user has authenticated?



via Chebli Mohamed

vendredi 19 août 2016

Image Upload not working in laravel 5.1

I am currently doing a project called Doctor Management System.In this project I am stuck because i cannot upload my image & cannot define where my image is situated.I want to show 2 hospital info per page but it gives me all the data.Please help me solving this. My Route file is

Route::get('/profile/{id}', array('as' =>'profile' ,'uses' => 'ProfileController@index'));
        //Route::get('/update', array('as' =>'update' ,'uses' => 'ProfileController@postUpdate'));

        Route::get('/profile/{profile_id}/edit', [
                    'uses' => 'ProfileController@getUpdate',
                    'as' => 'edit'
            ]);

        Route::post('profile/update', [
                    'uses' => 'ProfileController@postUpdate',
                    'as' => 'update'
            ]);

My Blade template is

<?php $active="profile"; ?>
@extends('admin.dashboard')
@section('content')
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        User Profile
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">User profile</li>
      </ol>
    </section>

<!-- Main content -->
    <section class="content">
      <div class="row">
        <!-- left column -->
        <div class="col-md-10">
          <!-- general form elements -->
          <div class="box box-primary">
            <div class="box-header with-border">
              <h3 class="box-title">Quick Example</h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form action="" role="form" method="post" enctype="multipart/form-data">
              <div class="box-body">
                <div class="form-group">
                  <label for="name">Name</label>
                  <input type="text" class="form-control" name="name" id="name"  value="">
                </div>
                <div class="form-group">
                  <label for="institute">Institute Name</label>
                  <input type="text" class="form-control" name="institute" id="institute"  value="">
                </div>

                <div class="form-group">
                  <label for="education">Degree</label>
                  <input type="text" class="form-control" name="education" id="education"  value="">
                </div>

                <div class="form-group">
                  <label for="specialty">Specialty</label>
                  <input type="text" class="form-control" name="specialty" id="specialty"  value="">
                </div>

                <div class="form-group">
                  <label for="phone">Mobile No.</label>
                  <input type="number" class="form-control" name="phone" id="phone"  value="">
                </div>

                <div class="form-group">
                  <label for="time">Visiting Time</label>
                  <input type="text" class="form-control" name="time" id="time"  value="">
                </div>

                <div class="form-group">
                  <label for="fee">Fee</label>
                  <input type="number" class="form-control" name="fee" id="fee"  value="">
                </div>

                <div class="form-group">
                <label for="division">Division</label>


                  <select name="division_id">
                  @foreach($divisions as $division)
                    <option value=""></option>
                    @endforeach
                  </select>

                </div>

                <div class="form-group">
                <label for="district">District</label>


                  <select name="district_id">
                  @foreach($districts as $district)
                    <option value=""></option>
                    @endforeach
                  </select>

                </div>

                <div class="form-group">
                <label for="dcategory">Category</label>


                  <select name="dcategory_id">
                  @foreach($dcategories as $dcategory)
                    <option value=""></option>
                    @endforeach
                  </select>

                </div>

                <div class="form-group">
                  <label for="image">Chose the picture</label>
                  <input type="file" class="form-control" name="image" id="image"  value="">
                </div>
              </div>
              <!-- /.box-body -->

              <div class="box-footer">
                <button type="submit" class="btn btn-primary">Submit</button>
                <input type="hidden" name="_token" value="">
                <input type="hidden" name="id" value="">
              </div>
            </form>
          </div>
          <!-- /.box -->

        </div>
        <!--/.col (left) -->
      </div>
      <!-- /.row -->
    </section>
    <!-- /.content -->
@endsection 

My controller is

public function getUpdate($id) {
        $divisions = Division::all();
        $districts = District::all();
        $dcategories = Dcategory::all();

        $profile = Auth::user();
        $doctor=Doctor::find($id);

        // $post = Post::find($post_id);
        // if(!$post) {
        //     return redirect()->route('blog.index')->with(['fail' => 'Post Not Found']);
        // }
        return view('admin.article.edit')
        ->with('divisions',$divisions)
        ->with('districts',$districts)
        ->with('dcategories',$dcategories)
        ->with('profile',$profile)
        ->with('doctor',$doctor);
    }

    public function postUpdate(Request $request ) {

        $this->validate($request, [
            'name' => 'required|max:120',
            'fee' => 'required|max:5',
            'division_id' => '',
            'district_id' => '',
            'dcategory_id' => '',
            'education' => '',
            'institute' => '',
            'specialty' => '',
            'hospital' => '',
            'time' => '',
            'phone' => '',
            'image' =>''            
            ]);

        $doctor = Doctor::find($request['id']);
        $doctor->name = $request['name'];
        $doctor->division_id = $request['division_id'];
        $doctor->district_id = $request['district_id'];
        $doctor->dcategory_id = $request['dcategory_id'];
        $doctor->institute = $request['institute'];
        $doctor->education = $request['education'];
        $doctor->specialty = $request['specialty'];
        $doctor->hospital = $request['hospital'];
        $doctor->phone = $request['phone'];
        $doctor->time = $request['time'];
        $doctor->fee = $request['fee'];

        $photo = Photo::find($request['id']);
        $upload='uploads/logo';
        $file=Input::file('file');
        $file->move('uploads', $file->getClientOriginalName());
        $photo->image = $request['image'];
        // $file = Input::file('pic');
        // $img = Image::make($request->file('pic')->getRealPath());
        // //$img = Image::make($file);
        // Response::make($img->encode('jpeg'));

        // $doctor->pic = $img;
        $doctor->update();
        $photo->update();

        return redirect()->route('profile')->with(['success' => 'Profile Successfully Updated']);

    }

Plz help me how can i upload my image in upload directory in public folder.



via Chebli Mohamed