laravel-4

How do I set up Bootstrap after downloading via Composer?

梦想的初衷 提交于 2019-12-17 18:13:58
问题 I'm a beginner with Composer, so I know little about it and have little experience with web application development. I was reading the Nettuts+ Tutorial, and have a basic question about Composer. { "require": { "laravel/framework": "4.0.*", "way/generators": "dev-master", "twitter/bootstrap": "dev-master", "conarwelsh/mustache-l4": "dev-master" }, "require-dev": { "phpunit/phpunit": "3.7.*", "mockery/mockery": "0.7.*" }, "autoload": { "classmap": [ "app/commands", "app/controllers", "app

Use Laravel to Download table as CSV

梦想与她 提交于 2019-12-17 17:39:21
问题 I am trying to export a database table using Laravel as a csv file. I would like the user to be able to select the Export as CSV button and download the table as a csv file. Currently I've gotten this code but It is not working: my button: <a href="/all-tweets-csv" class="btn btn-primary">Export as CSV</a> my route: Route::get('/all-tweets-csv', function(){ $table = Tweet::all(); $filename = "tweets.csv"; $handle = fopen($filename, 'w+'); fputcsv($handle, array('tweet text', 'screen name',

Laravel form model binding

ぃ、小莉子 提交于 2019-12-17 17:32:16
问题 I've been reading about this feature: http://laravel.com/docs/html#form-model-binding And it looks really neat, but there are couple of things that I'm not certain about. Do I need to put any code in the controller action to process this form? What does that look like? The model (User) I want to bind in my form has a separate table for addresses. So I want to be able to fill out the User model's fields, but also the fields for the related Address model. Can I do that with form-model-binding,

Laravel Creating Dynamic Routes to controllers from Mysql database

烂漫一生 提交于 2019-12-17 17:25:51
问题 I have the following table: group_pages in mysql database with page name route name : id name route -------------------- 0 About about 1 Contact contact 2 Blog blog what I am trying to do is to create dynamic routes in my : routes.php ? Where if I go to for example: /about it will go to AboutController.php ( which will be created dynamically) is that possible? is it possible to create a dynamic controller file? I am trying to create dynamic pages routes that links to a controller example i

Laravel Eloquent: Ordering results of all()

拈花ヽ惹草 提交于 2019-12-17 17:25:21
问题 I'm stuck on a simple task. I just need to order results coming from this call $results = Project::all(); Where Project is a model. I've tried this $results = Project::all()->orderBy("name"); But it didn't work. Which is the better way to obtain all data from a table and get them ordered? 回答1: You can actually do this within the query. $results = Project::orderBy('name')->get(); This will return all results with the proper order. 回答2: You could still use sortBy (at the collection level)

Replacement for File::mime() in Laravel 4 (to get mime type from file extension)

家住魔仙堡 提交于 2019-12-17 16:44:25
问题 Laravel 3 had a File::mime() method which made it easy to get a file's mime type from its extension: $extension = File::extension($path); $mime = File::mime($extension); On upgrading to Laravel 4 I get an error: Call to undefined method Illuminate\Filesystem\Filesystem::mime() I also can't see any mention of mime types in the Filesystem API docs. What's the recommended way to get a file's mime type in Laravel 4 (please note this is not a user-uploaded file)? 回答1: One solution I've found is to

Laravel Eloquent compare date from datetime field

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 16:42:01
问题 I want to get all the rows from a table through an expression: table.date <= 2014-07-10 But if the column contains a datetime let's say: 2014-07-10 12:00:00 But if I do: where('date', '<=', $date) it won't get the row. I guess this is because $date = 2014-07-10 which makes MySQL assume that it is 2014-07-10 00:00:00. In regular MySQL I would just do where DATE(date) <= $date What would be the equivalent using Laravel's Eloquent? 回答1: Laravel 4+ offers you these methods: whereDay() ,

MediumBlob in Laravel database schema

為{幸葍}努か 提交于 2019-12-17 16:35:40
问题 How can I create a Mediumblob within the Laravel schema builder ? In the docs it says : $table->binary('data'); // BLOB equivalent to the table But I need a MediumBlob otherwise the images get truncated at 64K; we are running MySQL. I know that Laravel's schema builder is DB agnostic, but is there a way to avoid the "native way" and if not how can i create a Mediumblob column ? 回答1: You can't. This issue suggests using raw queries to create such columns, so you should do something like this

Find or Create with Eloquent

做~自己de王妃 提交于 2019-12-17 16:27:12
问题 I have recently started working with Laravel and Eloquent, and was wondering about the lack of a find or create option for models. You could always write, for example: $user = User::find($id); if (!$user) { $user = new User; } However, is there not a better way to find or create? It seems trivial in the example, but for more complex situations it would be really helpfully to either get an existing record and update it or create a new one. 回答1: Below is the original accepted answer for:

Creating MYSQL Procedure in Laravel 4 Migrations

孤街浪徒 提交于 2019-12-17 16:19:37
问题 Is there a way to generate stored MYSQL procedures in a Laravel 4 migration? For example, here's a simple procedure generation query stored as a string (via a Heredoc) $query = <<<SQL DELIMITER $$ DROP PROCEDURE IF EXISTS test$$ CREATE PROCEDURE test() BEGIN INSERT INTO `test_table`(`name`) VALUES('test'); END$$ DELIMITER ; SQL; DB:statement(DB::RAW($query)); When Running this in a migration's up() function I get this error: 回答1: There are two major problems with your code DELIMITER is not a