laravel-4

Attaching a hasOne model to another Laravel/Eloquent model without specifying id

怎甘沉沦 提交于 2019-12-06 18:08:15
问题 Background Given we have the following two tables where type_id references a row in questionType : question id | type_id | description ---+---------+------------ 1 | 1 | A nice question .. | .. | .. questionType id | name ---+---------------- 1 | Multiple-choice .. | .. with the following Eloquent models: class Question extends Model { public function type() { return $this->hasOne( 'QuestionType', 'id', 'type_id' ); } } class QuestionType extends Model { } Question 1 How can I add a new

Route [Controller@method] not defined

喜夏-厌秋 提交于 2019-12-06 18:06:39
问题 I'm trying to create a form with a corresponding controller method which adds a new record to the DB. Laravel Version is 4.1 app/views/projects.blade.php <tr> {{Form::open(array('action' => 'ProjectController@createProject', 'method' => 'post'))}} <td>{{Form::text('project_number')}}</td> <td>{{Form::text('title')}}</td> <td>{{Form::text('client')}}</td> <td>{{Form::text('comment')}}</td> <td> {{Form::file('xmlfile')}}<br /> {{Form::submit('Hinzufügen',array('class' => 'blue'))}} </td> {{

Why does `catch (Exception $e)` not handle this `ErrorException`?

只愿长相守 提交于 2019-12-06 17:15:00
问题 I get the ErrorException on the function call bellow. How can this be? Why is it not caught? try { static::$function_name($url); } catch (Exception $e) {} The underlying reason for the error is a file_put_contents call. I'm using the Laravel 4 framework, if it makes any difference. 回答1: I suspect that you need to write this: try { static::$function_name($url); } catch (\Exception $e) {} Note the \ in front of Exception. When you have declared a namespace, you need to specify the root

Is it possible to pass a route parameter to controller constructor in Laravel?

断了今生、忘了曾经 提交于 2019-12-06 17:12:39
问题 Is it possible to inject a route-paramter (or an route segment) to the controller-constructor? You find some code to clarify my question. class TestController{ protected $_param; public function __construct($paramFromRoute) { $this->param = $paramFromRoute; } public function testAction() { return "Hello ".$this->_param; } } ---------------------------------------------------- App::bind('TestController', function($app, $paramFromRoute){ $controller = new TestController($paramFromRoute); return

How can I get the raw query string from Laravel's query builder BEFORE executing the query?

為{幸葍}努か 提交于 2019-12-06 17:00:26
问题 I have a complex query created by a few conditions, and I would like to get the final SQL query from the builder object is about to execute. Can I do that? 回答1: You can get it doing: $query = DB::table('brands') ->join('products','a','=','c') ->whereNull('whatever'); echo $query->toSql(); But Laravel will not show you parameters in your query, because they are bound after preparation of the query. So you can also do: print_r( $query->getBindings() ); 回答2: For debugging this might come quite

Pass an array to Redirect::action in laravel

浪尽此生 提交于 2019-12-06 15:51:43
I'm trying to pass an array from a function to another function in laravel. In my PageController.php , I have public function show($code, $id){ //some code if(isset($search)) dd($search); } and another function public function search($code, $id){ //some queries $result = DB::table('abd')->get(); return Redirect::action('PageController@show, ['search'=>$search]); } But this returns me an error like this: ErrorException (E_UNKNOWN) Array to string conversion I'm using laravel. You could maybe get it to work with passing by the URL by serialization, but I'd rather store it in a session variable.

Laravel & Couchdb-ODM - The annotation “@Doctrine\\ODM\\CouchDB\\Mapping\\Annotations\\Document” does not exist, or could not be auto-loaded

梦想与她 提交于 2019-12-06 15:34:25
I want to use couchdb-odm in Laravel 4.2 but I keep on getting errors. The last one is: [Semantical Error] The annotation "@Doctrine\ODM\CouchDB\Mapping\Annotations\Document" in class IO\Documents\Article does not exist, or could not be auto-loaded. I copied mostly the sandbox/bootstrap.php and tried a couple of recommendations from previous answers in the same problem. Here is currently what I have: My composer.json has: "require": { "laravel/framework": "4.2.*", "symfony/console": ">=2.0", "doctrine/dbal": "2.5.*@dev", "doctrine/migrations": "1.0.*@dev", "doctrine/common": "2.4.*", "doctrine

Laravel 4 eager loading and categories, subcategories, articles

房东的猫 提交于 2019-12-06 15:34:18
问题 Hi i thought i can handle this myself, but actually i don't know how to bite it. I am trying to categorise my programs. There will be only 2 levels of categories: 1 CATEGORY 2 |-Subcategory I want it to be as simple as possible. - program can belong to only one subcategory, - categories can have many subcategories, - subcategories can have many programs, Of course i would like to list all programs from subcategories, when someone choose a main category. I am also not sure about my current

How to make controllers, models, views outside app folder in Laravel 4?

早过忘川 提交于 2019-12-06 15:27:42
I want to make a structure folder like this: root/ admin/ controllers/ AdminController.php BaseController.php models/ views/ app/ ... etc I updated composer.json: "autoload": { "classmap": [ "app/commands", "app/controllers", "app/models", "admin/controllers", "admin/models", "admin/views", "app/database/migrations", "app/database/seeds", "app/tests/TestCase.php" ] }, And then run 2 commands: composer dump-autoload , php artisan dump-autoload and create a route: Route::get('/admin', 'AdminController@showWelcome'); . But when I hit http://localhost/laravel/admin , I get an error. Anyone can

Using multidimensional array input names with Laravel 4.2 Form facade throws error on postback

旧巷老猫 提交于 2019-12-06 15:01:39
I'm having an issue in Laravel 4.2 with the Form facade when using input names that represent multidimensional arrays. The form will load, display, and post data correctly unless there are values set in Input::old() (because of failed validation, etc.). Here is a simple example that shows the problem: routes.php: Route::get('input-test', function() { return View::make('input_test.index'); }); Route::post('input-test', function() { return Redirect::back()->withInput(Input::all()); }); input_test/index.blade.php: <!doctype html> <html> <head> <title>Input Array Test</title> </head> <body> {{