laravel-4

How to extend laravel 4 core?

人盡茶涼 提交于 2019-12-03 13:23:52
I am a newb learning laravel 4. I want to override specific helper functions. Or add new functions to Url, Str etc. How to do this? Depending on what part of Laravel you want to extend or replace, there are different approaches. Macros Adding functions to Str is really easy, because of "macros": Here's a short example for adding function: Str::macro('test', function($str) { return 'Testing: ' . $str . '!'; }); You can then call this function as expected: echo Str::test('text'); // Outputs "Testing: text!" Adding functions using macros are supported by Str, Form, HTML and Response . IOC Based

Defining the email address for the Mail::send() method

别说谁变了你拦得住时间么 提交于 2019-12-03 13:10:00
Apologies if I'm missing something here as I'm new to Laravel but when I send a closure to the Mail::send() method to define the mail recipient, it works fine if the email address is available the global scope, like this: Mail::send('frontend.emails.default', $data, function($message) { $message->to(Input::get('email'))->subject('Hi'); }); But how can I pass a value in that's scoped to the calling method? For example: $user = User::find($id); Mail::send('frontend.emails.default', $data, function($message) { $message->to($user->email)->subject('Hi'); }); I tried adding it to the $data array but

Laravel 4: how can I understand how it all works?

蓝咒 提交于 2019-12-03 13:03:31
问题 I am using Laravel 3 in one project and it's been a joy. I have also looked at the source code several times to see how some things work behind the scenes. But now in Laravel 4, I don't know where to begin or how to understand it all. Where can I learn all the behind the scenes of Laravel 4? Case in point: I wanted to find out if the DB::insert() returns the id of inserted row. So I started searching. 1. I found the Illuminate\Support\Facades\Facade class that "encapsulates" DB. 2. The

Laravel 4 Model class not found

£可爱£侵袭症+ 提交于 2019-12-03 12:59:53
问题 I just created a simple app in Laravel 4 and when I create a model, I get an exception that it's not found. // /app/models/Worker.php: <?php class Worker extends Eloquent {} And then in the Controller var_dump(Worker::find(1)); This gives me Error: Class 'Worker' not found. What am I doing wrong? This used to work in Laravel 3 and also watching the screencasts it seems like this should work. 回答1: Anytime you create a new class file in L4 run this command. php composer dump-autoload 回答2: I

How can I allow WYSIWYG editors and disable XSS attacks using Laravel?

你说的曾经没有我的故事 提交于 2019-12-03 12:57:52
问题 I have a enterprise level application where logged in users are authorized to post articles to page using a WYSIWYG editor. (You can consider this application as a website builder.) Everything works fine, but the problems are; WYSIWYG editor posts a HTML containing article, also some localised string characters which Laravel doesn't like, so Laravel's alpha_num check can't pass. (Therefore we don't use it on validation checks.) We need to allow characters like < , " , > because they may want

AngularJS: Reload ng-include after user authentication (or a better way to solve issue)

◇◆丶佛笑我妖孽 提交于 2019-12-03 12:55:28
问题 I am really just learning Angular and I am attempting to create an app that limits content access based on authentication. I have the authentication part working (also using the Laravel PHP framework), but I am having an issue "reloading" certain pieces of content based on auth status, namely after a successful authentication. Initially, what I am trying to do is update the main navigation menu after a user logs in. I am sure there is a better approach, but what I have so far is a view

Link with icon in Laravel 4

痞子三分冷 提交于 2019-12-03 12:45:01
Can someone help to rewrite this, from HTML to Laravel4? <a href="index.php" ><span><i class="icon-home"></i></span> Home </a> The route name for that page is just '/'. I know how to write simple link in Laravel: {{ HTML::link('/','Home) }} But how can I add the span class with the font-awesome icon? I'd just put the link in the href. <a href="{{ url('/') }}"><span><i class="icon-home"></i></span> Home</a> No need to generate all the rest through Laravel. What @Dries suggests is simple and very straightforward, but you really want to have it done entirely via Laravel, I would suggest writing a

Laravel 4 cannot run whole RAW queries

安稳与你 提交于 2019-12-03 12:34:20
I would like to use the DB class of laravel to execute a mysql query but none of the functions provided by Laravel are working. None of those is working: DB::statment() / DB::select() / DB::raw() / DB::update() / DB::select(DB::raw()) Here is the code I would like to query: DROP TABLE users; CREATE TABLE `users` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `u_username` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `u_email` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `password` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `u_regdate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',

mysql join ON and AND to laravel eloquent

左心房为你撑大大i 提交于 2019-12-03 12:32:24
I've been able to get the query result I need using the following raw sql: select `person`.`id`, `full_name`, count(actions.user_id) as total from `persons` left join `actions` on `actions`.`person_id` = `persons`.`id` and `actions`.`user_id` = $user where `type` = 'mp' group by `persons`.`id` But I haven't been able to get it working in eloquent yet. Based on some similar answers, I'd tried functions within ->where() or leftJoin() , but the count of each person's actions isn't yet being filtered by $user . As it stands: $query = Person::leftJoin('actions', function($q) use ($user) { $q->on(

Call shell commands from laravel controller?

老子叫甜甜 提交于 2019-12-03 12:28:45
Is it possible to call Shell commands (e.g for converting images ) from laravel controller? If yes then how. I have searched on internet. Nothing seems relevant. Please Guide. Thanks You can use the Process component provided by Symfony: http://symfony.com/doc/current/components/process.html The component is used by Laravel itself, so it can be loaded directly. If you use it(instead of php's exec() function), you'll be able to unit test the code that calls shell commands. It all depends on what operating system you are using. php already has a few functions to execute shell commands. Laravel