0

i have a route defined in my route.php file like this:

Route::get('{username}/{search_term}', 'userProfileSearchController@search');

in my controller i retrieve the user model from db by the username and then performing a search query for finding the results based on the passed term then i return to a view like below in my controller:

return view('view', compact('result'));

but the problem is it doesn't return the view properly.
of course it returns the view and pass the variable too but it affects the root url like this:

example.com/{username}/

and my stylesheets and scripts doesn't load on page because of the wrong url laravel is giving!
so they trying to load in page with this url:

example.com/{username}/js/jquery.js

UPDATE
this is my controller:

<?php

namespace App\Http\Controllers;

use App\User;
use App\Http\Requests;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Repositories\Interfaces\UserRepositoryInterface;

class SearchController extends Controller
{
     protected $user;

     public function __construct(UserRepositoryInterface $user)
     {
          $this->user = $user;
     }
     /**
      * Searching the user profile and sending the results
      *
      * @return \Illuminate\Http\Response
      */
      public function userProfileSearch($username, $search_term)
      {
           $result = $this->user->getUserProfileSearchResult($username, $search_term);
           return view('view', compact('result'));
      }
}

and my user repository method:

public function getUserProfileSearchResult($username, $search_term)
{
    $user = $this->user->where('username', $username)->firstOrFail();
    $userHomes = $user->homes()->searchUserHomes($search_term);
    return $userHomes;
}

and finally my model and the searchUserHomes scope:

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Home extends Model
{
     protected $table = 'homes';
     protected $fillable = ['street', 'city', 'zip_code', 'country', 'state', 'price', 'description'];
     protected $hidden = ['created_at', 'update_at'];

     public function scopeSearchUserHomes($query, $search_term)
     {
          $search_term = str_replace('-', ' ', $search_term);
          $query->where(function($query) use($search_term) {
               $query->where('street', 'LIKE', '%'.$search_term.'%');
          });
          for($i=1; $i<count($this->fillable); $i++)
          {
               $query->orWhere(function($query) use($i, $search_term){
               $query->where($this->fillable[$i], 'LIKE', '%'.$search_term.'%');
          });
      }
      return $query->get();
}
Aria
  • 45
  • 9
  • By redirect do you mean just returning the view or are you calling redirect() somewhere? It would be helpful to see the entire controller method. Does `php artisan route:list` show the correct route existing? Also, are scripts and styles heels loading correctly elsewhere on the site? – Josh Rumbut Nov 29 '15 at 10:51
  • Yes, please share the complete routes – Mina Abadir Nov 29 '15 at 10:52
  • yes they work correctly on other routes! but not here my problem is just why laravel makes the {username} wildcard part of the url and make it even root url for entire links and scripts even though i didn't use the laravel helper functions to load my assets and i just hard coded them! – Aria Nov 29 '15 at 13:52

0 Answers0