laravel-4

Laravel: Escape “LIKE” clause?

安稳与你 提交于 2019-12-10 02:38:47
问题 How can I escape a LIKE clause in Laravel/Eloquent? e.g., $search = Input::query('sSearch', ''); if($search !== '') { $paginatedBookings->where('first_name', 'LIKE', '%' . $search . '%'); } If $search contains a % or _ they need to be escaped. 回答1: The other answer forgets about escaping the escape character itself, here is a more robust solution: /** * Escape special characters for a LIKE query. * * @param string $value * @param string $char * * @return string */ function escape_like(string

Laravel blade templates, foreach variable inside URL::to?

强颜欢笑 提交于 2019-12-10 01:47:35
问题 I'm creating a basic list view of posts, and need a link to the 'edit' page. I'm using blade, and what I have is a table, with a foreach loop, showing each post along with edit/delete buttons. What I wanted to do is use blade's URL::to for the links to the edit and delete pages, to ensure consistant links. The code I've tried using (remember this is inside a foreach loop hence the $post->id var) is this: <a href="{{ URL::to('admin/posts/edit/$post->id') }}" class="btn btn-mini btn-primary"

How to set form input required attribute in laravel 4

自古美人都是妖i 提交于 2019-12-10 01:30:15
问题 I'm using the laravel framework for a project, and I'm implementing a basic form page, where I require certain values to be required , something that can be done very easily in HTML5. <input type="text" name="abc" required> In laravel, without the required attribute, the same would be : {{ Form::text('abc') }} How do I incorporate a required attribute in the above statement? 回答1: Since simply writing ['required'] did not work, I searched online a bit more and found the answer, so I thought I

Phonegap + Laravel 4 How to upload file

旧街凉风 提交于 2019-12-09 23:55:28
问题 I answered this question myself so that others don't face the problems i did. 回答1: The Client Side(Javascript Code) : It took me a while to figure out how to use the file upload feature in phonegap while using laravel 4 on the server. This is for others who might be looking for some help : Ensure that : public/images (or any other destination folder you wish to upload fie folder is writable or else you will get error code : 1 Values of options.fileKey must match Input::file(options.fileKey)-

Angular JS + Laravel 4: How to compile for production mode?

五迷三道 提交于 2019-12-09 23:52:38
问题 So i have watched the 5 part youtube videos by David Mosher about Angular JS (vids great by the way). In the part 2 (http://www.youtube.com/watch?v=hqAyiqUs93c), it has a practical mysql database usage which I almost wanted. I'm going to use AngularJS along with Laravel 4, but I had no idea which files I'm going to upload for the web hosting later . I'm trying to run the web app under "/public" folder in my root on localhost (localhost/public/) but the css and js points to the wrong directory

Artisan output buffer does not contain all output

China☆狼群 提交于 2019-12-09 23:11:07
问题 I'm using the following code to redirect the output of an artisan command within a route. use Symfony\Component\Console\Output\BufferedOutput; Route::get('/restart', function() { $output = new BufferedOutput; Artisan::call('remote:restart', array(), $output); return $output->fetch(); }); This works for most cases. However if within the command I use the SSH component to run some tasks on a remote server, the output resulting from SSH::into()->run() will be disregarded by the above code. If I

Save .JSON file to database using laravel

我只是一个虾纸丫 提交于 2019-12-09 20:59:36
问题 I am very new to Laravel and PHP in general, most of what I have worked on has been relative to online tutorials. I know how to save single items like a username or password to my database but I am clueless when it comes to storing an entire file.This is how my database is currently formatted in my migration file: public function up() { Schema::create('users', function(Blueprint $table) { $table->increments('id'); $table->string('username'); $table->string('email')->unique(); $table->string(

Laravel 4 - Input::old for radio buttons

柔情痞子 提交于 2019-12-09 18:15:07
问题 I was wondering if some Laravel guys can help out. I have a form in which i have 2 radio buttons, when the form submits it goes through the validator, if the validator fails it comes back to the form, populates the fields with the input and displays error messages. I cant seem to do this for radio buttons, if one is clicked when the form is submitted and there was an error, it comes back to the form with everything filled out EXCEPT the radio button that was checked is now empty. My radio

Laravel 4 - Return the id of the current insert

柔情痞子 提交于 2019-12-09 17:21:14
问题 I have the following query public static function createConversation( $toUserId ) { $now = date('Y-m-d H:i:s'); $currentId = Auth::user()->id; $results = DB::table('pm_conversations')->insert( array( 'user_one' => $currentId, 'user_two' => $toUserId, 'ip' => Request::getClientIp(), 'time' => $now ) ); return $results; } How would i return the id of the row just inserted? Cheers, 回答1: Instead of doing a raw query, why not create a model... Call it Conversation, or whatever... And then you can

Sessions not persisting in Lumen PHP framework

夙愿已清 提交于 2019-12-09 16:59:16
问题 I'm using the Lumen (by Laravel) micro-framework for a project, and I'm having some trouble with sessions. I'm just testing the implementation now, but the problem I'm experiencing is that when I set a session variable and then refresh the page, the variable is no longer set. In my .env file I have: SESSION_DRIVER=cookie And I know that this is being picked up, because when I change it to memcached it throws an error (because I don't have memcached set up). I've enabled the middleware too: