laravel-4

Basic Laravel 4 Routing

爷,独闯天下 提交于 2019-12-11 09:29:35
问题 I would like to call a controller with parameters with this kind of configuration: Route::pattern('d', '[0-9]+'); Route::get('/{a}/{b}/{c}/{d}', function($a, $b, $c, $d) { // CALL A METHOD OF A CONTROLLER WITH PARAMETERS }); 回答1: Just call the controller method like this: Route::get('/{a}/{b}/{c}/{d}', 'AnyController@itsMethod'); And in the controller: class AnyController extends BaseController { //... public function itsMethod($a, $b, $c, $d) { ///proceed your params } //... } Laravel passes

Laravel Relationship error trying to call a relationship within the model

好久不见. 提交于 2019-12-11 09:05:01
问题 On Laravel "4.1.x-dev", How can I call a method on a relation within the model? From the below example public function userLink() { return $this->user->link; } My function userLink gives me the error : Relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation Also is there another way for me to access the linked user from Drawing with some kind of eager loading trick? I have several different type of users . Each type of user has it's own table with an

PHP - Use database in MVC view layer (Laravel Blade)

自古美人都是妖i 提交于 2019-12-11 08:58:27
问题 Is it generally a good idea to interact with database in view layer in MVC frameworks? I'm using Laravel 4. I want to show some data from database at top of all website's pages. I have a main.blade.php and: @include("inc.header") If I should, how can I connect to database from inc/header.php in right way? I don't want make multiple connections one here at header.php and one in my pages controllers. I'm more familiar with PDO than Laravel's database methods and ORMs. Any advice is appreciated!

Laravel 4 how get routes by group name

做~自己de王妃 提交于 2019-12-11 08:32:24
问题 In Laravel, I know I can get all routes using `Route::getRoutes() but I can't find if it is possible to get a list of all routes contained in a specified group. For example, i have this route file: Route::group(array('group_name' => 'pages'), function() { Route::any('/authentication', array('as' => 'authentication', 'uses' => 'LogController@authForm' )); Route::group(array('before' => 'auth_administration'), function() { Route::any('/tags_category/index', array('as' => 'index-tags-categories'

Not getting connected to Sql Server 2012

被刻印的时光 ゝ 提交于 2019-12-11 08:31:53
问题 I am getting following error while connecting to Sql Server 2012 in Laravel 4 PDOException SQLSTATE[IMSSP]: This extension requires the Microsoft SQL Server 2012 Native Client ODBC Driver to communicate with SQL Server. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712 As per this link http://msdn.microsoft.com/en-us/library/cc296170.aspx I downloaded and installed these two files in xampp/php

Laravel routing group for muliple domains with wildcards, how to handle domain suffixes?

回眸只為那壹抹淺笑 提交于 2019-12-11 08:28:02
问题 I have 3 domains which, on my local server, take the format: mydomainfirst.local mydomainsecond.local mydomainthird.local In my routes.php file, I have the following: Route::group(array('domain' => '{domain}.{suffix}'), function() { Route::get('/', 'Primary@initialize'); }); The idea is to take the $domain variable in my controller and extract the first/second/third part from it, which works fine. However, now my site is online, this routing file no longer works and throws a Http-not-found

Laravel ManyToMany Multiple

旧城冷巷雨未停 提交于 2019-12-11 08:23:00
问题 I have 3 models: User , Role , Tool where each user could have many roles, and each role could have many tools. The many to many relationships work well in each case. I can access: User::find(1)->roles Tool::find(1)->roles Role::find(1)->tools Role::find(1)->users My tables are: users id name roles id name tools is name role_user id role_id user_id role_tool id role_id tool_id In each model: //In User Model public function roles() { return $this->belongsToMany('Rol'); } //In Role Model public

how to pass variables “$tid, $id” into raw function?

ⅰ亾dé卋堺 提交于 2019-12-11 08:20:26
问题 when i call $id and $tid in raw function to fetch some data from sub document of mongodb collection it show me an error these two variables are undefined($tid,$id) ? <?php $id=IntValue; $tId=IntValue; if($tId==0) { $maxPlayers=0; } else { $result = DB::collection('PrizeDistributionTemplate')->raw(function($collection) { return $collection->aggregate(array( array( '$match' => array( 'id' => $id,'templates.tId' => $tid) ), array( '$unwind' => '$templates' ), array( '$match' => array( 'id' =>

Laravel - Polymorphic many-to-many returns empty

对着背影说爱祢 提交于 2019-12-11 08:20:12
问题 I've been at this for 5 hours now and can't seem to figure out the mistake. I'm using Polymorphic Many-to-Many Relations in Laravel 4.1. A Job and an Event each can have a Tag and I've set up the stuff accordingly. But whenever I call $job->tags it returns empty. I have these 3 classes (BaseModel extends Eloquent, namespace is always App\Models, I have to reference them in the e.g. "morphToMany" function, doesn't work with "use"): class Job extends BaseModel { public function tags() { return

Laravel 4 - Unit Tests

丶灬走出姿态 提交于 2019-12-11 08:16:01
问题 I am trying to write unit tests for my application, I think I know how to test a GET request for example; The controller I am testing has the following function, which is supposed to get the 'account create view' public function getCreate() { return View::make('account.create'); } Also, this is referenced in the routes file like this /* Create account (GET) */ Route::get('/account/create', array( 'as' => 'account-create', 'uses' => 'AccountController@getCreate' )); and what I am doing for