laravel-4

Why Laravel still logging a NotFoundHttpException while all routes works?

混江龙づ霸主 提交于 2019-12-04 08:23:23
All my registered routes are working. They display the view, yet on every request a NotFoundHttpException shows up in my log file. I'm using NGINX. Could it be my NGINX config? The error that is logged on every request (even though the view shows up): log.ERROR: exception 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException' in /usr/share/nginx/www/example-staging/releases/20130815024541/vendor/laravel/framework/src/Illuminate/Routing/Router.php:1429 Stack trace: #0 /usr/share/nginx/www/example-staging/releases/20130815024541/vendor/laravel/framework/src/Illuminate/Routing/Router.php

Add item to select box with an Eloquent collection

拥有回忆 提交于 2019-12-04 08:08:16
I have a select box on a form which uses data that is listed from an Eloquent model (Laravel 4): $campuses = Campus::lists('name', 'id'); And the form: {{ Form::select('campus_id', $campuses) }} However, I would like to have the first option on the form be Select... so that when the user has not selected an option yet, the first option does not become the default. How can I prepend another option to the beginning of the Eloquent collection? I've tried something like: $campuses = array('Select...') . Campus::lists('name', 'id'); You could also do $campuses = array('' => 'Select...') + Campus:

Submit form laravel using AJAX

允我心安 提交于 2019-12-04 08:01:49
问题 I am trying to add comment using AJAX technology but I have an error: Failed to load resource: http://localhost:8888/blog/public/comment/add the server responded with a status of 500 (Internal Server Error) Here is my code: View: {{ Form::open(array('method'=>'post','class'=> 'col-md-6','url' => '/comment/add', 'id'=>'comment')) }} <input type="hidden" name="post_id" value="{{$id}}"> <div class="row"> <div class="inner col-xs-12 col-sm-12 col-md-11 form-group"> {{Form::label('name', 'Imię')}}

Laravel - Check if @yield empty or not

爷,独闯天下 提交于 2019-12-04 07:49:06
问题 Is it possible to check into a blade view if @yield have content or not? I am trying to assign the page titles in the views: @section("title", "hi world") So I would like to check in the main layout view... something like: <title> Sitename.com {{ @yield('title') ? ' - '.@yield('title') : '' }} </title> 回答1: There is probably a prettier way to do this. But this does the trick. @if (trim($__env->yieldContent('title'))) <h1>@yield('title')</h1> @endif 回答2: In Laravel 5 we now have a hasSection

Laravel Custom Model Methods

坚强是说给别人听的谎言 提交于 2019-12-04 07:48:29
问题 Whenever I add additional logic to Eloquent models, I end up having to make it a static method (i.e. less than ideal) in order to call it from the model's facade. I've tried searching a lot on how to do this the proper way and pretty much all results talk about creating methods that return portions of a Query Builder interface. I'm trying to figure out how to add methods that can return anything and be called using the model's facade. For example, lets say I have a model called Car and want

Validation errors in AJAX mode

女生的网名这么多〃 提交于 2019-12-04 07:46:14
问题 Currently I use this to display validation errors via ajax: if (data.validation_failed == 1) { var arr = data.errors; $.each(arr, function(index, value) { if (value.length != 0) { $("#validation-errors").append('<div class="alert alert-error"><strong>'+ value +'</strong><div>'); } }); $('#ajax-loading').hide(); $("#validation-errors").show(); } It works fine, does exactly what I need. The problem is what I have to do to transport the errors from laravel to ajax: $rules = array( 'name' =>

Many to many relationships with taxonomy in Eloquent

夙愿已清 提交于 2019-12-04 07:44:16
I'm using Laravel 4. I have many to many relationships in my system. And I choose to use Wordpress taxonomy table scheme. But how can I make models relationships with Laravel 4 Eloquent ORM? Here is my database tables; Table terms : +------------+---------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+---------------------+------+-----+---------+----------------+ | term_id | bigint(20) unsigned | NO | PRI | NULL | auto_increment | | name | varchar(200) | NO | MUL | | | | slug | varchar(200) | NO | UNI | | | +------------+----

How to handle User Registration via API Laravel

橙三吉。 提交于 2019-12-04 07:38:05
I have being reading and watching some tutorials about API development in Laravel. I am new to API development entirely although I have used Laravel a bit. From all the tutorials I have gone through, they handled: login, get some data, update information, delete information, and even insert some information into the database. My problem is that none of this tutorials handle something like a user registration. Route::group(array('prefix' => 'api/v1', 'before' => 'auth.basic'), function() { Route::resource('users', 'UsersController'); Route::resource('messages', 'MessagesController'); }); From

Preventing Laravel adding multiple records to a pivot table

一曲冷凌霜 提交于 2019-12-04 07:28:17
问题 I have a many to many relationship set up and working, to add an item to the cart I use: $cart->items()->attach($item); Which adds an item to the pivot table (as it should), but if the user clicks on the link again to add an item they have already added it creates a duplicate entry in the pivot table. Is there a built in way to add a record to a pivot table only if one does not already exist? If not, how can I check the pivot table to find if a matching record already exists? 回答1: You can

Laravel 4 blade templates causing FatalErrorException?

时光总嘲笑我的痴心妄想 提交于 2019-12-04 07:20:07
I'm getting an unexplained FatalErrorException when trying to implement a simple page layout using blade templating. I'm not sure if it's something I'm doing wrong or Laravel is. I'm following the tutorial on L4's documentation about Templating and my code seems to follow it. Here's my code. app/routes.php: <?php Route::get('/', 'HomeController@showWelcome'); app/views/home/welcome.blade.php: @extends('layouts.default') @section('content') <h1>Hello World!</h1> @stop app/views/layouts/default.blade.php: <!doctype html> <html> <head> <title>The Big Bad Barn (2013)</title> </head> <body> <div>