laravel-4

Clone an Eloquent object including all relationships?

天涯浪子 提交于 2019-12-28 03:31:14
问题 Is there any way to easily clone an Eloquent object, including all of its relationships? For example, if I had these tables: users ( id, name, email ) roles ( id, name ) user_roles ( user_id, role_id ) In addition to creating a new row in the users table, with all columns being the same except id , it should also create a new row in the user_roles table, assigning the same role to the new user. Something like this: $user = User::find(1); $new_user = $user->clone(); Where the User model has

Could not open input file: artisan

▼魔方 西西 提交于 2019-12-28 03:19:12
问题 When trying to create a new laravel project, The following error appears on the CLI: Could not open input file: artisan Script php artisan clear-compiled handling the post-install-cmd event returned with an error I am using the latest version of XAMPP v3.2.1 with PHP 5.5.15 and with mcrypt enabled (made sure of that by issuing the command php -m). And I am running windows 8.1 回答1: You need to first create Laravel project and if you already have one you need to go to this project dir using cd

Laravel 4: how to “order by” using Eloquent ORM [duplicate]

时光怂恿深爱的人放手 提交于 2019-12-28 02:23:48
问题 This question already has answers here : Laravel Eloquent: Ordering results of all() (8 answers) Closed 4 years ago . Simple question - how do I order by 'id' descending in Laravel 4. The relevant part of my controller looks like this: $posts = $this->post->all() As I understand you use this line: ->orderBy('id', 'DESC'); But how does that fit in with my above code? 回答1: If you are using post as a model (without dependency injection), you can also do: $posts = Post::orderBy('id', 'DESC')->get

How to get a list of registered route paths in Laravel?

空扰寡人 提交于 2019-12-28 01:51:32
问题 I was hoping to find a way to create an array with the registered routes paths within Laravel 4. Essentially, I am looking to get a list something like this returned: / /login /join /password I did come across a method Route::getRoutes() which returns an object with the routes information as well as the resources but the path information is protected and I don't have direct access to the information. Is there any other way to achieve this? Perhaps a different method? 回答1: Route::getRoutes()

Query Execution [closed]

半世苍凉 提交于 2019-12-27 03:35:45
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 3 years ago . How to execute this query in laravel. ? select d1.update_id from ( select update_id, count(update_id) as ct from updates_tags where tag_id in (67,33,86,55) group by update_id) as d1 where d1.ct=4 回答1: you can use Raw Queries in Laravel $results = DB::select(SELECT * FROM table WHERE id IN (1,2,3,4)

Laravel 4 Eloquent assign BIT values

会有一股神秘感。 提交于 2019-12-25 16:56:06
问题 I want to set a filed with BIT data type in mySql using Eloquent. $i = new Step; $i->active = 'b0'; $i->save(); But the active filed is 1 , I also tried: $i->active = "b'0'"; $i->active = '0'; $i->active = false; ... Simply I want to run something like this: INSERT INTO `steps` (`active`) VALUES (b'0') 回答1: Talking about active field: If you want to use active and inactive for flagging active and inactive state of any record (i.e. user model) then you may use tinyint data type. Bool, Boolean:

Laravel 4.2 execute query without using elequent query builder

荒凉一梦 提交于 2019-12-25 16:47:45
问题 I have a query with sub-query .. and i want to write an explicite SQL request and execute it Query : select count(*) as count from ( SELECT DISTINCT t.article_id FROM `articles` as a left join `tags` as t on a.`id` = t.`article_id` where a.`flag` = 1 ) as sub i tried this to execute the request without building the query : DB::connection()->getPdo()->exec( $sql ); But it always return 0 ! 回答1: You can use sub query with DB::raw . A method DB::raw() (don’t forget to use Illuminate\Support

Laravel 4.2 Session Table Not Getting Cleaned Up

。_饼干妹妹 提交于 2019-12-25 16:47:05
问题 I have a Laravel 4.2 app hosted on Bluehost and I'm trying figure out why the MySql session table never gets cleaned up. I've tried increasing the lottery but still no joy. Any ideas? Here are the relevant session.php settings: 'driver' => 'database', 'lifetime' => 180, 'expire_on_close' => true, 'lottery' => array(2, 100) 回答1: On every request Laravel uses the session lottery value to generate a random number that will determine if it will run the session garbage collection. The exact code

How to set base url to /subfolder in Laravel 4.2

醉酒当歌 提交于 2019-12-25 13:28:11
问题 I have uploaded my laravel 4.2 application to a /subfolder of a shared hosting like www.example.com/bangla by following this answer. Structure of my application is example.com/ (the root of your web hosting) |-- laravel4_base/ (Here goes all contents except public folder) |-- [some other folders...] |-- public_html/ | |-- [some other folders...] | |-- bangla/ (Here goes contents of public folder) Now i have these menu link in my view <li><a href="/">Home</a></li> <li><a href="/rj">Rj</a></li>

How to set base url to /subfolder in Laravel 4.2

倾然丶 夕夏残阳落幕 提交于 2019-12-25 13:28:07
问题 I have uploaded my laravel 4.2 application to a /subfolder of a shared hosting like www.example.com/bangla by following this answer. Structure of my application is example.com/ (the root of your web hosting) |-- laravel4_base/ (Here goes all contents except public folder) |-- [some other folders...] |-- public_html/ | |-- [some other folders...] | |-- bangla/ (Here goes contents of public folder) Now i have these menu link in my view <li><a href="/">Home</a></li> <li><a href="/rj">Rj</a></li>