routing,routes,laravel-5,friendly-url,slug , Is it possible in laravel 5 to show a pretty url to the user, and a practical url to the app?


Is it possible in laravel 5 to show a pretty url to the user, and a practical url to the app?

Question:

Tag: routing,routes,laravel-5,friendly-url,slug

I have this url: mywebsite.com/user/1/edit

I want my users to see this: mywebsite.com/edit-your-profile/

Is this possible when using Route::resource('user', 'UserController');? If yes, how do I do it :) ? I still want my app to be able to see user/1/edit as I use it in my middleware to prevent unauthorized access:

if ( \Auth::user()->id != $request->segment(2) ) {

    return  redirect()->back();

}

So, one pretty url for my user, a practical one for my app.


Answer:

Based on your explanation, I take that a user can only edit their own profile. So mywebsite.com/user/1/edit should NOT even be allowed. Instead, add this in your Route.php add: Route::get('/edit-your-profile','[email protected]'); and hardcode \Auth::user()->id into your editController and do not even allow the user to set the id. Why bother asking them for an ID if you already know what the id must be and ALL other ids will be rejected!

PS. The html form for update should be at @update and the output that form should be sent to @edit. I just wanted to simplify the routing in the example.


Related:


No route matches [Post] /characters/1/edit


ruby-on-rails,ruby,routes
I am trying to reach the edit page for my character class, but for some reason it is routing with a POST when it should be a GET. All similar questions have not helped. Here is my edit function: def edit end Here are my routes: <%= button_to 'Edit Character',...

using dart route package url got error 404


routes,dart
Here's my main.dart: import 'dart:html'; import 'package:route/client.dart'; import 'urls.dart'; void main() { var router = new Router() ..addHandler(homeUrl, showHome) ..addHandler(galleryurl, showGallery) ..listen(); HttpRequest.getString("home.html").then((html){ querySelector("#container").innerHtml = html; }); } void showHome(String path){ HttpRequest.getString("home.html").then((html){ querySelector("#container").innerHtml = html; }); } void showGallery(String path){ HttpRequest.getString("gallery.html").then((html){...

Angular $routeProvider and Controller As Syntax


angularjs,routing,angularjs-scope,angularjs-routing,ngroute
Can anyone tell me if it is valid to use $routeProvider with Controller as syntax? I am having issues accessing <h1>{{kickController.foo}}</h1> from the controller where this.foo resides. angular.module('ucp.kick', ['ngRoute']).config(function($routeProvider, APP_BASE_URL) { return $routeProvider.when(APP_BASE_URL + 'kicks', { reloadOnSearch: false, navitem: true, name: 'Kicks', templateUrl: 'kick/partials/kick.html', controller: 'kick as KickController' }); });...

Open page url in modal on a page (Facebook Photo URLs)


javascript,jquery,angularjs,routing,angularjs-routing
P.S. I am using html5Mode to remove '#' in routing in below scenario Removing the hashtag from AngularJS urls (# symbol) Consider I have two main pages.One is photos where thumbnails are provided and whose url is /someSlug/photos. Other is the url of a single photo '/someSlug/photos/somePhotoId' which shows a...

Why does this MVC action return a 404 response in IE11


ajax,asp.net-mvc,routing
I have written an mvc action that works in Chrome and Firefox but not in IE11. Using IE11 it returns a 404 response code. Controller: [HttpDelete] public ActionResult DeleteAction(int ActionID) { return Json(_Logic.DeleteAction(ActionID), JsonRequestBehavior.DenyGet); } Calling JS: Ajax_Proxy.DeleteAction = function (_actionID, successCallback, failureCallback) { return $.ajax({ type: "DELETE", datatype: 'json',...

Where should I put Symfony third-party bundle's routing configuration?


php,symfony2,routing,symfony-routing
I have SonataAdminBundle, SonataUserBundle and LiipImagineBundle installed in my Symfony 2 application. According to their installation instruction, I put their routing configuration in /app/config/routing.yml. _liip_imagine: resource: "@LiipImagineBundle/Resources/config/routing.xml" admin: resource: "@SonataAdminBundle/Resources/config/routing/sonata_admin.xml" prefix: /admin _sonata_admin: resource: . type: sonata_admin prefix: /admin sonata_user: resource: '@SonataUserBundle/Resources/config/routing/admin_security.xml' prefix: /admin...

Routes work in Development But not in Production


ruby-on-rails,routes
Weird Error. I have some routes that work perfectly during development but once i deploy and try to access them it comes up with page does not Exist error I have the following routes.rb file: TransportUnl::Application.routes.draw do resources :trucks resources :shipments do collection do get :autocomplete_location_cs end end devise_for :users...

Symfony/Twig how to render a Route set by anotation?


php,symfony2,routing,twig,url-routing
Let's say I have this code in a controller: <?php namespace Foo\BarBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration as Mvc; /** * @Mvc\Route("/foo/bar") */ class TestController extends Controller /** * @Mvc\Route("/test/{id}", requirements={"id" = "[0-9]{1,6}"}) * @Mvc\Template * * @return view */ public function testAction($id) { return array('test' => $id); } } How...

How to access UrlHelper.Action or similar from within Global asax


c#,routing,asp.net-mvc-5
I am trying to prepare a 301 redirect for a typo I made 'recieved' I am struggling to find a way of getting the url from the action and controller names. I am aware of UrlHelper.Action but it does not exist within Global.asax. How do I gain access to this...

Rails - SEO friendly URLs with Self joined models


ruby-on-rails,routes
Right now there are two models: Category and Product. Categories are self joining to make sub_categories. Category has_many Product, who of course belongs_to Category. The question I have is this: How Do I map the routes for these resources so that they have SEO friendly URLS. For example: If the...

Redirect to a homepage cakephp 3


php,redirect,routes,cakephp-3.0
I've followed the articles tutorial from cakephp 3 website and created the website http://i.imgur.com/JMh1Pwv.png Now there is add article, delete article and edit article actions. When I delete an article it redirect me to http://localhost:8888/test/articles/delete/14 Here is the delete code. public function delete($id) { $this->request->allowMethod(['post', 'delete']); $article = $this->Articles->get($id); if...

Pass array on url using zend framework 2 routes


php,zend-framework,routes,zend-framework2
I have a web app that lets user make multiple searches and show the results of that searches all on the same page. Here's a basic structure: Search 1 - Attribute 1 = X - Attribute 3 = Y Search 2 -Attribute 2 = Z All these results are loaded...

How to add menus/ subtopics for meteor site?


javascript,node.js,meteor,routing,meteor-blaze
I am new to meteor. I followed the tutorials and successfully making simple interfaces like below. I tried finding examples to add menus/ subtopics like this which does not reload the page when clicked, but I couldn't find any examples. Could you please give me an example how to do...

Route parameter with slash “/” in URL


asp.net-web-api,routing,asp.net-web-api2,asp.net-web-api-routing,attributerouting
I know you can apply a wildcard in the route attribute to allow / such as date input for example: [Route("orders/{*orderdate}")] The problem with wildcard is only applicable to the last paramter in URI. How do I solve the issue if want to have the following URI: [Route("orders/{orderdate}/customers")] ? EDIT:...

$StateProvider Remove Child View Nesting


angularjs,routing,angular-ui-router,angularjs-ui-router
I am new to angular ui routing . I am creating a sample application and want to display parent and child view separately . I mean when parent item gets selected child view will be displayed and parent view would be hidden . If I add ui-view to parent view...

Check if file exists for ng-include in $routeProvider template


javascript,html,angularjs,node.js,routes
I've setup my Angular routes to use the slug from the URL to determine what file to load. It looks like this: $routeProvider.when("/project/:slug", { controller: "ProjectController", template: function($routeParams){ return '<div id="project" ng-include="\'/views/' + $routeParams.slug + '.html\'"></div>'; } }); Works a charm, but there's no fallback here if the file for...

Change resources path


ruby-on-rails,ruby,routing
I'm using Rails 4 I have a routes.rb file that looks like: resources :books However, I'd like the urls in the application to end up looking like /b/101 instead of /books/101. I realize I could go through and rename each resource path individually, but is there not a way to...

How to change the 'micropost feed' URL from Rails Tutorial?


ruby-on-rails,routes
I'm following Michael Hartl's book 'Rails Tutorial' and need to change the logged in URL to render at /members instead of at the site's root. I've tried changing home.html.erb from: <% if logged_in? %> <div class="row"> <aside class="col-md-4"> <section class="user_info"> <%= render 'shared/user_info' %> </section> <section class="stats"> <%= render 'shared/stats'...

Rails routing link to specific show


ruby-on-rails-4,routing
This question seems a little basic, but considering I have 'pages#show' with a show page with url 'history'. How could I add this specific show page to a link: = link_to 'History', pages_path(@?????) PD1: I would prefer avoid using :id since I tend to seed a lot of data, and...

Get Path from array in Rails 4


ruby-on-rails,ruby-on-rails-4,routes
I wonder is there possibility to get path from array outside views (in my case in model) like in link_to method - link_to 'User', [:admin, @user] . For example I want to store admin_artist_path (unfortunately real problem is more complex because I can't predict what path will be ) class...

Preserve `$location.search()` in angular `redirectTo`?


javascript,angularjs,routes
How can I preserve $location.search() with $routeProvider.otherwise({redirectTo: xxx}) I know, I can use a function there, which gets the old object $location.search() as the third argument. I mostly care about a single key, let's call it a, and I tried function(a, b, search) { return "/mainpage?a=" + search[a]; } but...

Rails Devise Routes: If user signed in, point to index. Else, point to new user session


ruby-on-rails,ruby,if-statement,devise,routes
Pretty simple question, but I can't seem to find the answer with a good ole fashioned Google. The error: undefined method `user_signed_in?' for #<ActionDispatch::Routing::Mapper:0x007fc6369320e8> (NoMethodError) Server won't even start. My code: Rails.application.routes.draw do devise_for :users, :path_prefix => 'u' resources :users devise_scope :user do get "login", to: "devise/sessions#new", as: :login get...

Restrict laravel to open url that is not in route


php,laravel,routing,laravel-5,laravel-5.1
I am Learning laravel now. Today I came across a problem that surprised me. I open this link in my browser: http://localhost/laravel/project/ch/resources/views/pages/blog.blade.php And I expect error 404. but it opens contains of this file. So, How to restrict laravel to do this. I want laravel to open only url mentioned...

Route Not Working in Rspec


ruby-on-rails,rspec,routes
Given the follow rails route ... post '/a/link.aspx', to: 'vendor_simulator#an_action' and the route shows as ... Prefix Verb URI Pattern Controller#Action POST /a/link.aspx(.:format) vendor_simulator#an_action And the following passing test ... it "returns http success" do post :an_action, return_xml, :content_type => 'application/xml' expect(response).to have_http_status(:success) end Why does the following test fail...

current_page? in a _partial view keeps erroring


ruby-on-rails,ruby,routes
I'm using a _form partial which contains my Create and Edit template for my model Products. I have the following code to check if it's the Edit View <% current_page?(edit_product_path(@product)) %> However when I enter the create view the site falls over with the following error No route matches {:action=>"edit",...

Select Mongoose Model Based on Express Route


express,routing,mongoose
I think this might be a basic question, but looking for the best approach. I'm building an express app that should route to one of four different Mongoose models depending on the route. Something like this: app.get('/:trial', function(req, res){ var trial = req.params.trial; trial.find(function(err, records) { if (err) res.send(err); res.json(records);...

Render a 'micropost feed' from the Rails Tutorial in a custom location/view?


ruby-on-rails,routes,custom-routes
I followed Michael Hartl's 'Rails Tutorial' book and need to render the 'micropost feed' at a custom location (/members) instead of at the site's root. I've updated the SessionsController so that when a user logs in they are redirected to the new /members URL, but there are two statements needed...

Route Generation error for :create action in Minitest


ruby-on-rails,routes,params,minitest
I am currently writing functional tests for all of my controllers. For every single one, I can't get the create action to work. I keep getting the following error when I run rake test: ActionController::UrlGenerationError: No route matches {:action=>"create", :comment=>{:content=>"I'm a comment.", :product_id=>"685617403"}, :controller=>comments} Here is the action I am...

Laravel - multiple routes


php,laravel,routes
I'm doing a simple project. I want it to be as minimal as possible so I tried to create system where I can create pages and they're placed at localhost/{page?} But, here's the problem. I also want some routes to be defined (e.g. route /blog) like below. Route::get('/{page?}', ['as' =>...

Multiple routes with multiple domains


symfony2,routing
Let's say I've got a website with multiple (sub)domains: acme.com (USA) acme.nl (Netherlands) be.acme.eu (Belgium) de.acme.eu (Germany) fr.acme.eu (France) etc... I thought this should be very simple to configure, so I made this routing.yml: usa: host: "acme.com" resource: "@WebsiteBundle/Controller/" type: annotation defaults: country: "en" netherlands: host: "acme.nl" resource: "@WebsiteBundle/Controller/" type:...

How to handle one express route different than all other


javascript,node.js,express,routes
I'm currently using the Express router within a NodeJS application. I have simply been using app.use(app.router); for routing and it works well. However, I'm now testing out some new routes and want to handle them differently. Ideally I would like to be able to say: var vers2Router = require('./routes/version2'); app.use('/version2',...

How to deal with extra “/” in phpleague route?


php,web-services,routing
I am setting endpoints for my web application like this: $router = new League\Route\RouteCollection; function user_action (Request $request, Response $response) { // some logic . . . return $response; } $router->addRoute('GET', '/user', 'user_action'); /user endpoint works well. However when I use /user/ (extra slash in the end) I get a...

Laravel 5 form submit creates an error MethodNotAllowedHttpException


php,forms,controller,routes,laravel-5
I'm using Laravel 5. When editing a form a get this error MethodNotAllowedHttpException There are a few posts but I think it may be code specific. I'd rather not use the resource route methods if possible. Route: Route::get('profile/edit', array('as' => 'admin.profile.edit', 'uses' => '[email protected]')); Route::post('profile/edit', array('as' => 'admin.profile.update', 'uses' =>...

No action was found on the controller that matches the request


c#,asp.net,ajax,asp.net-mvc,routing
Sorry for the lame question. I've already read all similar questions and still can't resolve my issue. I'm getting 'No action was found on the controller that matches the request' error when calling from ajax: $.ajax({ url: '/api/ToyEdit/Post/', dataType: "json", type: "POST", contentType: 'application/json; charset=utf-8', data: JSON.stringify({toyId: 1, toy: 'asd'}),...

Is it possible in laravel 5 to show a pretty url to the user, and a practical url to the app?


routing,routes,laravel-5,friendly-url,slug
I have this url: mywebsite.com/user/1/edit I want my users to see this: mywebsite.com/edit-your-profile/ Is this possible when using Route::resource('user', 'UserController');? If yes, how do I do it :) ? I still want my app to be able to see user/1/edit as I use it in my middleware to prevent unauthorized...

Asp.net MVC Routelink null controller parameter


c#,asp.net,asp.net-mvc,asp.net-mvc-4,routing
I have two routes, the default one routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); I added another route, sometimes the parameter will by a string routes.MapRoute( name: "ByName", url: "{controller}/{action}/{name}", defaults: new { controller = "Home", action =...

Node forward path request to another server


node.js,express,routing,routes,request
Currently have a website running a node server that handles all requests for example.com and I created a completely separate wordpress blog on a separate server (running apache) that I would like served on a path like example.com/blog at 172.23.23.23 IP address. The wordpress server doesn't share any code or...

Re-transmission concept in TCP


tcp,routing,tcp-ip,osi
Server sent data to client, but client didn't send ACK for the data . So once RTT completed , Server will resend data to client again .... like that how long it will try to send the data ? What is the maximum time server will try to send the...

ASP.NET MVC routing 404


asp.net,json,asp.net-mvc,routes
I have add a new route in a default mvc project like this: routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); routes.MapRoute( name:"test", url:"{controller}/{userId}/{action}/{cardId}", defaults: new {controller="User", userId=UrlParameter.Optional, action="card", cardId=UrlParameter.Optional } ); And I have a action method like...

Adding authorization to routes


ruby-on-rails,rest,routes,authorization
I cannot seem to find a good example for this. I have for example, a TicketController I define a ticket resource in my routes.rb. You only need to be logged in as a customer to GET a ticket, but you must be logged in as an administrator to PUT a...

Reload controllers after scope change (AngularJS)


javascript,angularjs,view,routes,scope
so I have this controller for swapping languages app.controller("langCtrl",['$scope','$route',function($scope,$route){ this.swap_lang = function(){ if(lang == "tr"){ lang = "en"; }else{ lang = "tr"; } console.log(lang); this.lang = lang; //$route.reload(); //$scope.$apply(); }; }]); And this one below is supposed to be responsible for bringing up menus (JSON files with short language codes)...

WebApi Routing not working for Post


routing,asp.net-web-api2,asp.net-web-api-routing
My WebApiConfig has following routes // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { controller = "Employee", action = "Get", id = RouteParameter.Optional } ); The Post WebApi method has got following Signatures [HttpPost] public IHttpActionResult Post(Employee emp) { ..... } When i try to call...

Showing a username in the URL


angularjs,twitter-bootstrap,routes
I have a single page Angular + bootstrap app where the user can enter their username (no password) into a text input and their user info will be displayed on screen. I wish to make it so that when a user's info is displayed on the screen, the URL changes...

I don't understand routing


php,routing,flightphp
I am trying to learn a PHP framework. But I'm having some difficulties understanding some of the concepts of routing. I've chosen to use Flight. Their homepage shows: require 'flight/Flight.php'; Flight::route('/', function(){ echo 'hello world!'; }); Flight::start(); And I don't understand what they're using Flight::route... for. What am I missing?...

How to correctly use Express 4 multiple routers


javascript,node.js,express,routes
I'm attempting to use the Express 4 Router to use a different router based on the path. I want all /api/v2/ routes handled by version2, and every other route handled by version1. The below setup serves me all the version1 routes correctly, but seems to ignore version2 as I get...

SAPUI5/OPENUI5 - Routing with Dialogs


routing,dialog,sapui5,openui5
I´m currently stuck with the combination of routing and dialogs. I have a view with list elements and when I click on an element in the list I want the Detail view to be shown in a Dialog (Popup). The thing is, I also want the ID of the list...

Trying to Delete Message from List with Rails


ruby-on-rails,model-view-controller,routes
So I have a simple list of messages that users can submit. I'm trying to put a delete button (that works) for each message. But as you can see here you get an error about an entirely different action if you click the button. I'm not totally sure about where...

Codeigniter Select JSON, Insert JSON


json,codeigniter,select,insert,routing
I have very simple users database: user_id, user_name, user_email My model this: class Users extends CI_Model { private $table; private $table_fields; private $table_fields_join; function __construct() { parent::__construct(); $this->table = 'users'; $this->table_fields = array( $this->table.'.user_id', $this->table.'.user_name', $this->table.'.user_email' ); $this->table_fields_join = array(); } function select(){ $this->db->select(implode(', ', array_merge($this->table_fields, $this->table_fields_join)));...