laravel-4

laravel how to route to a route on a javascript?

ぐ巨炮叔叔 提交于 2019-12-07 05:24:04
问题 I have this jquery $(".waitingTime .button").click(function () { alert("Ema"); }); I have a a tag like this: <a href="{{ URL::to('restaurants/20') }}"></a> Can I do the same href action in the jquery function? Many Thanks 回答1: yes this is possible and has nothing to do with Laravel. There are different possibilities. If your query is embedded within the same laravel view, you put the URL directly in your jQuery code, for example like this: $(".waitingTime .button").click(function () { window

Laravel - Add trailing slash with Redirect::route()

浪子不回头ぞ 提交于 2019-12-07 05:23:59
问题 I'm trying to add a slash to the end of the URL after I use Redirect::route() with Laravel. I've tried numerous examples but couldnt find an answer. This is what I have so far: routes.php : Route::get('/', function() { return Redirect::route('login'); }); Route::get('/login/', array( 'as' => 'login', 'uses' => 'Controller@login' )); Controller.php : public function login() { return 'Login page'; } When I go to htdocs/laravel_project/ , I get redirected to htdocs/laravel_project/login but I

nginx - laravel - hhvm-Fastcgi get error 500

霸气de小男生 提交于 2019-12-07 05:17:41
问题 I install a LEMP server in ubuntu 12.04 LTS 64 whit HHVM Fastcgi Service and i install laravel via laravel.phar ( and test via composer too ) when in get my site in brwoser do not display any error but in chrome developer console get error 500 i can't see any error in error.log file ( laravel - hhvm , nginx ) the storage directory Permissions is 777 and my nginx.conf and vhosts file have basic configuration when i use PHP CLI or hhvm command it's worked good thanks for help me :) my location

mockery->shouldReceive() passing when it shouldnt?

被刻印的时光 ゝ 提交于 2019-12-07 05:17:19
问题 I am learning unit testing in laravel using phpunit and mockery. I am currently trying to test UsersController::store(). I am mocking User Model and using it to test the index method and that seems to work. When I take out $this->user->all() the test fails and when its in it passes. When testing the store method though I am using the mock to test that the user model receives validate() once. The store method is empty but the test passes. I have left out the irrelevant pieces of the class for

Relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation from model call by not view in Laravel 4

荒凉一梦 提交于 2019-12-07 04:51:13
问题 I have a model, Ability, which belongs to another model AbilityType. <?php class Ability extends Eloquent { public function abilityType() { return $this->belongsTo('AbilityType'); } public function name() { return $this->abilityType->name; } } I can make this call in my blade template successfully: $ability->abilityType->name But when I make that same call in my Ability model, it throws an exception: ErrorException Relationship method must return an object of type Illuminate\Database\Eloquent

Laravel 4: How to add scope to DB::table?

烈酒焚心 提交于 2019-12-07 04:18:58
问题 With Eloquent models adding scopes is easy: public function scopeMyScope($query) { // Do stuff to that $query } But how to add scope to DB::table ? I use this query to get page views: $views = DB::table('page_views') ->where('id', $this->id) ->where('agent', 'NOT LIKE', '%bot%') ->count(DB::raw('distinct session, DATE(created_at)')); I also show the most popular pages etc with other queries, but with the same where conditions. So I would like to only define my where conditions once and reuse

Laravel 4 how check if a route only comes/redirected from another route?

亡梦爱人 提交于 2019-12-07 04:18:03
问题 Say i have localhost/public/admin that redirects immediately to localhost/public/user/login . How am I going to get the admin value in user/login ? 回答1: You'll need to grab the referer and check if it is contains 'admin'. Try the following $referer = Request::referer(); // or // $referer = Request::server('HTTP_REFERER'); if (strpos($referer,'admin') !== false) { dd('coming from admin') } Edit #1: As pointed out by @tomvo you can also use URL::previous() instead of Request::referer() in L4

Regular expression route constraint for a resource route

偶尔善良 提交于 2019-12-07 03:41:37
问题 Laravel offers the possibility to add regular expression constraint to a route like this: Route::get('user/{name}', function($name) { // }) ->where('name', '[A-Za-z]+'); it is also possible to create multiple routes for a resource: Route::resource('photo', 'PhotoController'); I want to add regular expression constraint only to the route GET /photo/{id} is that possible? 回答1: As far as I know you can't but you may mimic that using something like this (route filtering): public function _

Laravel 5 - View [home] not found

我的梦境 提交于 2019-12-07 02:33:44
问题 I ran composer update and now I'm running into an issue. I'm getting this error when I'm trying to load my home view: InvalidArgumentException in FileViewFinder.php line 140: View [home] not found. Yes, files exists in my directory (resources/views, etc.). Name is home.blade.php . My controller: <?php namespace Hulahoop\Http\Controllers; use Hulahoop\Http\Requests; use Hulahoop\Http\Controllers\Controller; use Illuminate\Http\Request; class HomeController extends Controller { /** * Display a

Test logged in user has correct id in Laravel 4

送分小仙女□ 提交于 2019-12-07 02:32:13
问题 I'm trying to work out how to test that the logged in user in Laravel 4 can visit the correct user account. At the moment this is what is in my routes.php file. Route::get('user/{id}', array('before' => 'auth', function(){ // logged in user // but can visit any account!! })); How would I restrict this to so user/1 could only see the profile if that is the current logged in users id? Auth::user()->id Returns the logged in id to test against but I can't work out how to write a filter that