laravel-4

laravel 4 -> get column names

荒凉一梦 提交于 2019-12-17 16:14:31
问题 How to get column names of a table in an array or object in Laravel 4 , using Schema, DB, or Eloquent. It seems that I can't find a ready to use function, maybe you have some custom implementations. Thx. 回答1: New Answer At the time I gave this answer Laravel hadn't a way to do this directly , but now you can just: $columns = Schema::getColumnListing('users'); Old Answer Using attributes won't work because if you do $model = new ModelName; You have no attributes set to that model and you'll

Laravel 4 - including a “partial” view within a view (without using Blade template)

£可爱£侵袭症+ 提交于 2019-12-17 16:07:00
问题 In Laravel 3, I used to do this. <?php render('partials.header'); ?> This was done in "PHP" views, without using Laravel's Blade templates. What's the equivalent of this in version 4? I tried <?php @include('partials.header'); ?> This doesn't work. If I do @include('partials.header') I have to save my file as ".blade.php" How do I include a "subview" without using the blade template? 回答1: There are different ways to include a view within a view in Laravel 4. Your choice will depend on any one

How can I get the session ID in Laravel?

牧云@^-^@ 提交于 2019-12-17 16:02:12
问题 I want to get the id of the session in Laravel 4 In Laravel 3, it was a bit hacky, but possible with this code: $session_id = Session::$instance->session['id']; But I can't work it out in Laravel 4... referencing the Session::$instance object throws errors: Access to undeclared static property: Illuminate\Support\Facades\Session::$instance have tried: $session_id = Session::get('id'); but to no avail.. any ideas? 回答1: Depends on the version of Laravel: Laravel 3: $session_id = $_COOKIE[

How can I change the size of a Bootstrap checkbox?

久未见 提交于 2019-12-17 16:01:07
问题 Wondering if its possible to change the size of checkbox as it's possible with buttons. I want it to be bigger, so it makes it easy to press. Right now its looking like this: Code: <div class="form-group"> <label class="col-md-7 control-label">Kalsiumklorid: </label> <div class="col-md-5" > {{ Form::checkbox('O_Kals_Klor', 1 , array('class' => 'form-control' )) }} </div> </div> 回答1: Or you can style it with pixels. .big-checkbox {width: 30px; height: 30px;} 回答2: It is possible in css, but not

Laravel validation: exists with additional column condition - custom validation rule

冷暖自知 提交于 2019-12-17 15:57:35
问题 Is there is a way of referencing another field when specifying the exists validation rule in Laravel? I want to be able to say that input a must exist in table a, input b must exist in table b AND the value for column x in table b must equal input a. Best explained by example: public $rules = array( 'game_id' => 'required|exists:games,id', 'team1_id' => 'required|exists:teams,id,game_id,<game_id input value here>', 'team2_id' => 'required|exists:teams,id,game_id,<game_id input value here>' );

Laravel ORM from self referencing table get N level hierarchy JSON

北城余情 提交于 2019-12-17 15:54:13
问题 I am using LARAVEL 4 with MySQL back-end. I have a self-referencing table with columns id, name, type and parent . Here, parent is foreign-key of the column Id . The data in table is as below : id name type parent 1 General group NULL 2 What is..? question 1 3 aa answer 2 4 bb answer 2 5 cc answer 2 6 How is..? question 1 7 ba answer 6 8 bb answer 6 9 Where is..? question 4 10 ca answer 9 11 cb answer 9 12 Who is..? question 6 13 da answer 12 14 db answer 12 15 Specific group NULL 16 When is.

Laravel change input value

倾然丶 夕夏残阳落幕 提交于 2019-12-17 15:36:03
问题 In laravel, we can get the input value via Input::get('inputname') . I try to change the value by doing this Input::get('inputname') = "new value"; . But then, I get the error message saying Can't use function return value in write context . Is it possible for us change the input value so that when later calling on Input::get('inputname') will get the new amended value? Thanks. 回答1: You can use Input::merge() to replace single items. Input::merge(['inputname' => 'new value']); Or use Input:

Laravel: Where to store global arrays data and constants?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 15:26:47
问题 I just started working with Laravel. I need to rewrite a whole system I made some years ago, using Laravel 4 as base framework. In my old system I use to have a constant.php file with some constants declared, and a globals.php file which contained lots of array sets (For example, categories statuses, type of events, langs, etc.). By doing so, I could use something like foreach ( $langs as $code => $domain ) { // Some stuff } anywhere in my app. My question is, how can I store that info in the

Laravel: Returning the namespaced owner of a polymorphic relation

十年热恋 提交于 2019-12-17 15:23:54
问题 I can find a number of discussions regarding this but no clear solution. Here are two links, although I will cover everything in my own question here. Github Issues Laravel.io discussion Simple Explanation This is a simple explanation of my problem for anyone already familiar with Laravel's polymorphic relationships. When using $morphClass, the contents of $morphClass which is saved in the database as the morph "type" is used for the classname when trying to find the owner of a polymorphic

Laravel Form methods VS traditional coding

女生的网名这么多〃 提交于 2019-12-17 12:48:30
问题 I am currently learning Laravel and finding it really useful and interesting. At the moment I am making a simple online application form. What are the biggest advantages to doing things using the Laravel syntax like: {{ Form::open(array('url' => 'foo/bar')) }} As opposed to simply: <form action="foo/bar"> Or: echo Form::text('username'); Instead of: <input type="text" name="username" /> The Laravel way must be better, I just wish to know why exactly? 回答1: Using built-in HTML helpers have many