samedi 29 septembre 2018

Images are not loading after Transferred Laravel Website on server

I have transferred website from local to web server, mean while i changed some scenarios.

1- I have changed folder structure and moved public folder files on root.

2- Image files are being uploaded into store folder while symbolic storage folder is moved on root also.

But after moving public folder files on root images not working. while uploaded images are being stored into main storage folder. but not linked with symbolic storage folder. so help me how can i attach again both storage folders.

Storage folder related code into config/filesystem is shown below:

'disks' => [

    'local' => [
        'driver' => 'local',
        'root' => storage_path('app/pulic/images/'),
    ],

    'public' => [
        'driver' => 'local',
        'root' => storage_path('app/public'),
        'url' => env('APP_URL').'/storage',
        'visibility' => 'public',
    ],

    's3' => [
        'driver' => 's3',
        'key' => env('AWS_KEY'),
        'secret' => env('AWS_SECRET'),
        'region' => env('AWS_REGION'),
        'bucket' => env('AWS_BUCKET'),
    ],

],

main storage folder path is:

Root/Laravel_files/storage/app/public/images

while symbolic storage folder address is:

Root/storage/images



via Chebli Mohamed

jeudi 27 septembre 2018

Laravel: Why does eager loading only keep results for last model?

If I execute the following:

App\Assignment::with(['unit.records' => function ($q) {
                    $q->where('process_date', '>=', '2016-01-01')
                        ->where('process_date', '<=', '2018-09-27')
                        ->orderBy('process_date')
                        ->orderBy('process_hour')
                        ->limit(1);
                    }])
                    ->whereIn('id', [9])
                    ->get();

Then I get the following result:

Illuminate\Database\Eloquent\Collection {#1104
 all: [
   App\Assignment {#1112
     id: 9,
     unit_id: 6,
     start_date: "2015-11-25",
     end_date: "2016-01-04",
     unit: App\Unit {#986
       id: 6,
       records: Illuminate\Database\Eloquent\Collection {#945
         all: [
           App\Record {#853
             id: 6624,
             unit_id: 6,
             process_date: "2017-09-19",
             process_hour: 14,
           },
         ],
       },
     },
   },
 ],
}

Note how the loaded unit has a record that matches the query.

Now, if I use the exact same query but add another assignment (49) to my whereIn array:

App\Assignment::with(['unit.records' => function ($q) {
                    $q->where('process_date', '>=', '2016-01-01')
                        ->where('process_date', '<=', '2018-09-27')
                        ->orderBy('process_date')
                        ->orderBy('process_hour')
                        ->limit(1);
                    }])
                    ->whereIn('id', [9,49])
                    ->get();

The record for assignment 49 is shown, but the record for assignment 9 does not show up anymore:

Illuminate\Database\Eloquent\Collection {#1032
 all: [
   App\Assignment {#1014
     id: 9,
     unit_id: 6,
     start_date: "2015-11-25",
     end_date: "2016-01-04",
     unit: App\Unit {#1283
       id: 6,
       records: Illuminate\Database\Eloquent\Collection {#1254
         all: [],
       },
     },
   },
   App\Assignment {#1061
     id: 49,
     unit_id: 29,
     start_date: "2017-02-24",
     end_date: "9999-12-31",
     unit: App\Unit {#1279
       id: 29,
       records: Illuminate\Database\Eloquent\Collection {#1131
         all: [
           App\Record {#1284
             id: 6062,
             unit_id: 29,
             process_date: "2017-03-10",
             process_hour: 13,
           },
         ],
       },
     },
   },
 ],
}

The record that matches the criteria for assignment 9 obviously exists, but for some reason it doesn't get loaded when the query finds more than one assignment with a unit/record that matches the criteria.

I tested this with more assignments as well, and in each case the record will only show up for the last assignment in the array.

What's the deal here?



via Chebli Mohamed

mercredi 26 septembre 2018

Laravel-echo socket polling failed

I trying to implement socket connection in my laravel5.1 web application My web app running in docker containers.

I have setup laravel-echo-server using [kylestev/laravel-echo-server][1], and its running as expected

enter image description here

import Echo from "laravel-echo"
window.io = require('socket.io-client');

if (typeof io !== 'undefined') {
    window.Echo = new Echo({
        broadcaster: 'socket.io',
        host: window.location.hostname + ':6001',
    });
}

window.Echo.channel('test-event')
    .listen('Eventname', (e) => {
        console.log(e);
});

when i load the page in browser the polling request failing with EMPTY_RESPONSE error.

enter image description here

    {
    "authHost": null,
    "authEndpoint": null,
    "database": "redis",
    "databaseConfig": {
        "redis": {
            "port": "6379",
            "host": "redis"
        },
        "sqlite": {
            "databasePath": "/database/laravel-echo-server.sqlite"
        }
    },
    "devMode": true,
    "host": "hms.zuzurooms.local",
    "port": "6001",
    "protocol": "http",
    "socketio": {},
    "sslCertPath": "",
    "sslKeyPath": "",
    "sslCertChainPath": "",
    "sslPassphrase": "",
    "subscribers": {
        "http": true,
        "redis": true
    },
    "apiOriginAllow": {
        "allowCors": false,
        "allowOrigin": "",
        "allowMethods": "",
        "allowHeaders": ""
    }
}



via Chebli Mohamed

dimanche 23 septembre 2018

why i am getting No query results for model in laravel?

When i search by city name which is available in my database table it will show the result but when i search by unknown city which is not available in my database table it says -No query results for model [App\City]. i am sharing you the code and screenshot see error screenshot actually i want to redirect to 401 page if the city is not found in my database table

Here is my route

Route::get('teacher-jobs-by-city/{city}','TeacherJobsController@by_location');

Here is my function

public function by_location($location_id='') {

$data= array();
$location = City::where('slug',$location_id)->where('status','1')->firstOrFail();
$items= Subject::orderBy('id','asc')->get();
$data['location']=$location;

      //$subjects = [''=>'Select Subject'] + Subject::lists('subject_title','id')->toArray();
      //$city = [''=>'Select City'] + City::lists('name','id')->toArray();
        $active_class ='Select Subject to see job Openings';
        return view('frontend.teacherjobs.by_location',compact('active_class','data','items'));

    }



via Chebli Mohamed

samedi 22 septembre 2018

Laravel: Sorting Polymophic Relations

REQUIREMENTS

  1. In the Student Controller, the results must be sorted by student name.

  2. The results must be sorted by student's guardian name.



TABLE STRUCTURE

  • taxonomies

    • id
    • entity_type - It contains the class name of the owning model.
    • entity_id - It contains the ID value of the student.
  • students

    • id
    • name
  • guardians

    • id
    • student_id
    • name



CONTROLLER

  • StudentController.php

    public function getStudents()
    {
        return Taxonomy::with([
                'entity', 
                'entity.guardian'
            ])
            ->where('entity_type', 'Student')
            ->get();
    }
    
    



MODEL

  • Taxonomy.php

    public function entity()
    {
        return $this->morphTo();
    }
    
    
  • Student.php

    public function taxonomies()
    {
        return $this->morphMany('App\Taxonomy', 'entity');
    }
    
    public function guardian()
    {
        return $this->hasOne('App\Guardian');
    }
    
    
  • Guardian.php

    public function student()
    {
        return $this->belongsTo('App\Student');
    }
    
    


via Chebli Mohamed

jeudi 20 septembre 2018

Auth.password class is not found

Laravel version: 5.1

This is a project which started in L4.2. I upgraded it to L5.1 and I am trying to fix issues. The app has its own password reset functionality which utilizes laravel reset() function.

I am trying to call Password::reset() but I am getting the error of password reset class is not found. I have the Illuminate\Auth\Passwords\PasswordResetServiceProvider::class and alias password registered in config app file but I am still getting the error auth.password class not found.



via Chebli Mohamed