laravel-4

Laravel Validation - number must start with 0 (zero)

。_饼干妹妹 提交于 2019-12-08 03:33:01
问题 How to do input validation that a number must start with 0? For example: $rules = [ 'full_name' => 'required|min:6', 'number' => 'required|numeric|min:5', ]; On the number field, it is requred, must be numberic only and minimum of 5 digits. I also need to include rule that it must start with 0? 回答1: Use laravel regex:pattern validator, inside an array (Issue with Laravel Rules & Regex (OR) operator) and a regex of something like this: /^[0][0-9]{4,}/ 回答2: You can try it with substr(Input::get

How to get a Builder object from rows related to pivot - Laravel

眉间皱痕 提交于 2019-12-08 03:32:59
问题 I'm trying to get all the "books" that one user have: but I can't do it how I need. I use the following code: /*Gets all books from the user whose id is 1*/ $books= User::find(1)->books(); That return to me an Collection object; but I need a Builder object, as I get when I use the "select" method. /* This code return me a "Builder" object */ Books::select(array('id', 'name', 'type')); I need the Builder instead of Collection because I using Bllim/Datatables on my project and this package just

Laravel 4 validation in bootstrap modal

荒凉一梦 提交于 2019-12-08 03:32:56
问题 I'm a newbie to Laravel 4, and I'm trying to get a form validation in bootstrap modal. My modal have a form with a text input and a submit button, and I want that when the validation fails, the modal show me the error. But the modal, after the validation and the page refresh, is closed. Here is the code from the controller and the view: Controller code: public function postAvatar() { $avatar_rules = array( 'avatar_src' => 'url', ); $validator = Validator::make(Input::all(), $avatar_rules);

How to register a namespace in laravel 4

寵の児 提交于 2019-12-08 02:14:45
问题 The problem: class PostRepostioryInterface not found for line 4 in PostController.php or in tinkering with the namespace I've even got class App\Models\Interfaces\PostRepositoryInterface not found The questions: How to register a namespace in laravel 4? What do I need to do to get L4 to recognise the classes/interfaces at this namespace? Larave 3 had a $namespaces static object in ClassLoader where you could add namespaces by Autoloader::namespaces(array( 'App\Models\Interfaces' => path('app'

Laravel 4 - Use a controller action in other controllers?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 02:13:50
问题 well I had a few controllers that were doing my jobs, now I created a few more controllers; some where in middle of an action in new controller, I just remembered that I've written the proper code in old controllers. so for e.g. in oldController@handyAction some_good_codez(); and in newController@newAction $myOldController = Load::controller('oldController'); // I wish Laravel had this? $myOldController->handyAction(); 回答1: This is wrong. Controllers have to have just one responsibility:

Laravel 4 Form::open set action

别说谁变了你拦得住时间么 提交于 2019-12-08 01:48:40
问题 I'm currently trying out Laravel 4 and I have created a resource controller. In the 'edit' function I'm building a form, which should post to the 'update' function. To create the form open tag I use the Form::open() function which recently got added to Laravel 4 it seems. But when I just do Form::open() the action of the form is the current url and I can't figure out how to change the action. I tried Form::open('clients/' . $client->id) but this gives me the following error: ErrorException:

Laravel 4 : Pagination and Sort Header

╄→尐↘猪︶ㄣ 提交于 2019-12-08 01:42:52
问题 I am having a problem with Laravel Pagination and Header Sort, Let me show you what I have. My current page I am working with is "admin/admins" where i have pagination and headers. 1) AdminController code: // get for admin/admins page // page to list all the Admin users public function getAdmins($sort= NULL , $sort_dir = NULL) { // CACHE SORTING INPUTS $allowed = array('first_name', 'last_name', 'email', 'activated', 'created_at'); // add allowable columns to search on $sort = in_array($sort,

How can a Laravel 4 class detect that it is running in an Artisan task vs. a browser request?

Deadly 提交于 2019-12-08 01:18:02
问题 I have some application boot code that needs to know if it is currently running in an artisan task vs. being called in a browser request. How do I detect this in Laravel 4? 回答1: Here is the best way to do it :) if (App::runningInConsole()) echo "Running in artisan/CLI"; else echo "Running in a browser"; Hope it helps. 回答2: runningInConsole() also returns true when unit tests are running, then I think a better way to detect if your app is running only through artisan is: if (App:

Laravel with mssql (sqlsrv) not connecting

自作多情 提交于 2019-12-08 00:21:37
问题 I was working on laravel with mysql it was working fine. But I have another scenario now. I need to connect the laravel to ms sql database which is reside on windows server. I have used the following code to connect to the DB app/config/database.php 'default' => 'sqlsrv', 'sqlsrv' => array( 'driver' => 'sqlsrv', 'host' => 'IP ADDRESS', 'database' => 'DB Name', 'username' => 'Username', 'password' => 'password', 'prefix' => '', ), but its showing error saying that PDOException could not find

Getting the name of the foreign key with eloquent

与世无争的帅哥 提交于 2019-12-07 23:56:02
问题 This must be very basic stuff but I can't seem to find out how to do it. I have a one to many relationship between to tables: Unit and Army (an army contains many units) and these are my models: class Army extends Eloquent { protected $guarded = array(); public static $armies = array(); protected $table = 'armies'; public function units() { return $this->hasMany('Unit'); } } and: class Unit extends Eloquent { protected $guarded = array(); public static $units = array(); protected $table =