Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8484265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:20:02+00:00 2026-06-10T20:20:02+00:00

By default we generally search any entry on db table by id number. But

  • 0

By default we generally search any entry on db table by id number. But I could not find how to search any entry by the name column.

This is my code for finding entry and rendering it to view

Controller : Authors

class Authors_Controller extends Base_Controller {

    public $restful = true;

    public function get_view($id){
        $authorModel = Authors::find($id);
        return View::make('authors.view')
            ->with('author', $authorModel)
            ->with('title', $authorModel->name);
    }

}

Model : Authors

<?php 

class Authors extends Eloquent {
    public static $table = 'authors';
}

Route :

Route::controller(Controller::detect());

Route::get('author/(:any)', array('as'=>'author', 'uses'=>'authors@view'));

View :

@layout('main.index')

@section('content')
<h1>{{$author->name}}</h1>

<p>
    {{$author->bio}}
</p>

<small>
    {{$author->created_at}} |
    {{HTML::link(URL::$base.'/authors/', 'Go back')}}
</small>
@endsection

How do i make the url as not to display id but to display the name of the post like

some.com/category/name (instead of some.com/category/id)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:20:04+00:00Added an answer on June 10, 2026 at 8:20 pm

    In your controller you are always going to search by $id as your Eloquent query uses:

    $authorModel = Authors::find($id);
    

    As your named route can be supplied with an int or string (:any) run a type check in the controller on $id and run a different query based on the result.

    public function get_view($id)
    {
       if (is_numeric($id))
       {
           $authorModel = Authors::find($id);
       }
       else
       {
           $column = 'name'; // This is the name of the column you wish to search
    
           $authorModel = Authors::where($column , '=', $id)->first();
       }
    
       return View::make('authors.view')
                    ->with('author', $authorModel)
                    ->with('title', $authorModel->name);
    
    }
    

    I hope that helps you.

    As a side note, your Eloquent model.

    There is no need for you to supply a table name if you use correct naming conventions.

    class Author extends Eloquent {
    
    }
    

    Note the singular Author will map to a table called Authors automatically without any intervention from you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

You might not know this, but pressing the F4 key on a ComboBox makes
More generally how do you rename Sphinx default elements (e.g. Quick Search to Search
The default strongly-typed Edit page in ASP.NET MVC 3 generally exposes all fields for
Just a general curiosity question. Why is this namespace System.Collections.Generic added by default in
Default JVM uses maximum 1.5 GB RAM/JVM Java application. But my Server have 8
The default markdown syntax for code blocks is indented by 4 spaces on each
By default, the ordered list looks like this: There are some spacing on the
Is there a list of the default Eclipse keyboard shortcuts? I'm generally looking for
What setting(s) in a Visual Studio 2005 project could cause the build to not
Is there any reason to switch from the default scope (transient?) to something else,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.