laravel 5.2 - which URL pattern is better, action/id or id/action -


i know of these 2 patterns better:

/photos/123/edit 

or

/photos/edit/123 

currently using first, gives me whoops, looks went wrong. when try /photos/123/editxx instead of 404 not found.

routes:

i unsure mistake, these photos routes:

route::get('photos/randpics','photoscontroller@randpics'); route::get('photos/{id}/edit','photoscontroller@getedit')->middleware(['auth']); route::post('photos/{id}/edit','photoscontroller@postedit')->middleware(['auth']); route::post('photos/{id}/retag', ['as' => 'photos.retag', 'uses' => 'photoscontroller@retag'])->middleware(['auth']); route::post('photos/{id}/delete','photoscontroller@delete')->middleware(['auth']); route::get('photos/{id}/albums', 'photoscontroller@getalbums')->middleware(['auth']); route::post('photos/{id}/albums', 'photoscontroller@postalbums')->middleware(['auth']); route::get('photos/{id}/detail','photoscontroller@detail'); route::get('photos/{id}','photoscontroller@single'); route::post('photos/like', 'photoscontroller@postlike')->middleware(['auth']); route::post('photos/unlike', 'photoscontroller@postunlike')->middleware(['auth']); route::get('photos','photoscontroller@index'); 

getedit() , postedit():

the same error, complaining undefined variable in master layout template appears, when enter /photos/123/a/a/a/ example.

public function getedit(request $request, $id = null) {     $pic = pic::findorfail($id);      if(gate::denies('edit-pic',$pic)) {         abort(403);     }      $pic->text = htmlspecialchars($pic->text);      $years = array_combine(range(date("y"), 1960), range(date("y"), 1960));      $location = $pic->location;     $tags = $pic->tags;     $tagsarray = $pic->tagnames();     $albums = $pic->albums;      $locations = array();     $getlocations = location::orderby('city')->get();     foreach($getlocations $gl)     {         $locations[$gl->id] = $gl->city.' ('.$gl->country.')';     }      $cats = cat::lists('cat','cat')->all();      return view('photos.edit',compact('pic','location','tags','tagsarray','albums','locations','cats','years')); }   public function postedit(request $request, $id = null) {     $pic = pic::findorfail($id);      if(gate::denies('edit-pic',$pic)) {         abort(403);     }      $this->validate($request, [         'title'    => 'max:200',         'text'     => 'max:3000',         'location' => 'required|exists:locations,id',         'cat'      => 'required|exists:cats,cat',         'jahrprod' => 'date_format:y'     ]);      $pic->title = trim($request->input('title'));     $pic->text = trim($request->input('text'));     $pic->jahrprod = ($request->input('jahrprod')) ? $request->input('jahrprod') : null;     $pic->location_id = $request->input('location');     $pic->cat = $request->input('cat');     $pic->save();      #mail     $maildata = array(         'msg' => 'picture '.$id.' ( '.$request->input('title').' ) edited '.auth::user()->username     );      mail::send(['text' => 'emails.empty'], $maildata, function($message){         $message->to('xx@yy.de')->from('xx@yy.de')->subject('picture edited');     });      return back()->with('success','photo information updated'); } 

controller.php

it seems, more 2 url segments, controller.php not working properly. /domain.xy/1/2 shows 8 /domain.xy/1/2/3 throws error undefined variable: photos_online

<?php  namespace app\http\controllers;  use illuminate\foundation\bus\dispatchesjobs; use illuminate\routing\controller basecontroller; use illuminate\foundation\validation\validatesrequests; use illuminate\foundation\auth\access\authorizesrequests;  use auth; use cache; use db;  use app\pic; use app\upload;  use carbon\carbon;  class controller extends basecontroller {     use authorizesrequests, dispatchesjobs, validatesrequests;      public function __construct()     {         dd(8);         //.......     } } 

if follow laravel's resource controller guidelines https://laravel.com/docs/5.2/controllers#restful-resource-controllers

you should go first one.

but fix problem show route , controller function handling it.

update

open appserviceprovider located in app/http/providers , replace boot() function this

public function boot() {     //initilizw $photos_online     $photos_online = cache::rememberforever('index_countpics', function()      {          return pic::count();      });       #pics today      if (cache::has('pics_today')){          $pics_today = cache::get('pics_today');      }else{          $pics_today = pic::whereraw('date(created_at) = date(now())')->count();          cache::put('pics_today', $pics_today, carbon::tomorrow());      }       # count waiting uploads      $waiting_uploads = cache::rememberforever('waiting_uploads', function()      {          return upload::where('accepted',0)->where('infos',1)->count();      });       # user online      $client_ip = request()->ip();       $check = db::table('useronline')->where('ip', $client_ip)->first();       $username = (auth::guest()) ? null : auth::user()->username;      $displayname = (auth::guest()) ? null : auth::user()->displayname;       if(is_null($check)){          db::table('useronline')->insert(['ip' => $client_ip, 'datum' => db::raw('now()'), 'username' => $username, 'displayname' => $displayname]);      }else{          db::table('useronline')->where('ip', $client_ip)->update(['datum' => db::raw('now()'), 'username' => $username, 'displayname' => $displayname]);      }       db::delete('delete useronline date_sub(now(), interval 3 minute) > datum');       $users_online = db::table('useronline')->wherenotnull('username')->get();      $guests_online = db::table('useronline')->count();       #unread messages      $unread_messages = 0;      if(auth::check()){          $unread_messages = auth::user()->newthreadscount();      }       view()->share('photos_online',$photos_online);      view()->share('pics_today',$pics_today);      view()->share('waiting_uploads',$waiting_uploads);      view()->share('users_online',$users_online);      view()->share('guests_online',$guests_online);      view()->share('unread_messages',$unread_messages); } 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -