laravel-blade

Best Practices for Laravel 4 Helpers and Basic Functions?

本秂侑毒 提交于 2019-11-27 05:46:23
I'm trying to understand the best place to put a global function in Laravel 4. For example, date formatting. I don't think making a facade is worth it as facades are too modular. I've read articles about creating a library folder and storing classes there but that also seems like a lot for a simple function. Shouldn't a 'tool' like this be available in Blade templates? What are the best practices for something like this and how do I make it available to Blade templates? The ugly, lazy and awful way: At the end of bootstrap/start.php , add an include('tools.php') and place your function in that

Passing data from controller to view in Laravel

守給你的承諾、 提交于 2019-11-27 05:04:00
Hey guys I am new to laravel and I have been trying to store all records of table 'student' to a variable and then pass that variable to a view so that I can display them. I have a controller - ProfileController and inside that a function: public function showstudents() { $students = DB::table('student')->get(); return View::make("user/regprofile")->with('students',$students); } In my view I have this code <html> <head></head> <body> Hi {{Auth::user()->fullname}} @foreach ($students as $student) {{$student->name}} @endforeach @stop </body> </html> I am receiving this error : Undefined variable

Laravel Escaping All HTML in Blade Template

冷暖自知 提交于 2019-11-27 04:34:52
I'm building a small CMS in Laravel and I tried to show the content (which is stored in the DB). It is showing the HTML tags instead of executing them. Its like there is an auto html_entity_decode for all printed data. <?php class CmsController extends BaseController { public function Content($name) { $data = Pages::where('CID', '=', Config::get('company.CID')) ->where('page_name', '=', $name) ->first(); return View::make('cms.page')->with('content', $data); } } I tried to print the content using the curly brace. {{ $content->page_desc }} and triple curly brace. {{{ $content->page_desc }}} And

What is the difference between {{ }} and {!! !!} in laravel blade files?

喜夏-厌秋 提交于 2019-11-27 01:31:45
In the laravel framework we can use blade to add PHP code in html file. We are using both {{ }} and {!! !!} syntax in blade files of Laravel. What is the difference between them? Narendrasingh Sisodia Blade {{ }} statements are automatically sent through PHP's htmlentities function to prevent XSS attacks. If you pass data from your Controller to a View with some HTML styling like: $first = "<b>Narendra Sisodia</b>"; And it is accessed, within Blade, with {{ $first }} then the output'll be: <b>Narendra Sisodia</b> But if it is accessed with {!! $first !!} then the output'll be: Narendra Sisodia

Calculate difference between two dates using Carbon and Blade

孤人 提交于 2019-11-26 16:48:51
问题 Does anyone know how to pass a given variable instead the Carbon's default parameters ? The documentation of Carbon says: // CARBON SAMPLE $dtToronto = Carbon::createFromDate(2012, 1, 1, 'America/Toronto'); $dtVancouver = Carbon::createFromDate(2012, 1, 1, 'America/Vancouver'); echo $dtVancouver->diffInHours($dtToronto); // 3 And i want to do something like this in my controller: // EXAMPLE $date = "2016-09-16 11:00:00"; $datework = Carbon::createFromDate($date); $now = Carbon::now();

Best Practices for Laravel 4 Helpers and Basic Functions?

那年仲夏 提交于 2019-11-26 11:44:38
问题 I\'m trying to understand the best place to put a global function in Laravel 4. For example, date formatting. I don\'t think making a facade is worth it as facades are too modular. I\'ve read articles about creating a library folder and storing classes there but that also seems like a lot for a simple function. Shouldn\'t a \'tool\' like this be available in Blade templates? What are the best practices for something like this and how do I make it available to Blade templates? 回答1: The ugly,

Laravel Escaping All HTML in Blade Template

和自甴很熟 提交于 2019-11-26 11:15:41
问题 I\'m building a small CMS in Laravel and I tried to show the content (which is stored in the DB). It is showing the HTML tags instead of executing them. Its like there is an auto html_entity_decode for all printed data. <?php class CmsController extends BaseController { public function Content($name) { $data = Pages::where(\'CID\', \'=\', Config::get(\'company.CID\')) ->where(\'page_name\', \'=\', $name) ->first(); return View::make(\'cms.page\')->with(\'content\', $data); } } I tried to

Is there any way to compile a blade template from a string?

主宰稳场 提交于 2019-11-26 09:54:52
问题 How can I compile a blade template from a string rather than a view file, like the code below: <?php $string = \'<h2>{{ $name }}</h2>\'; echo Blade::compile($string, array(\'name\' => \'John Doe\')); ?> http://paste.laravel.com/ujL 回答1: I found the solution by extending BladeCompiler. <?php namespace Laravel\Enhanced; use Illuminate\View\Compilers\BladeCompiler as LaravelBladeCompiler; class BladeCompiler extends LaravelBladeCompiler { /** * Compile blade template with passing arguments. * *

What is the difference between {{ }} and {!! !!} in laravel blade files?

我们两清 提交于 2019-11-26 09:44:01
问题 In the laravel framework we can use blade to add PHP code in html file. We are using both {{ }} and {!! !!} syntax in blade files of Laravel. What is the difference between them? 回答1: Blade {{ }} statements are automatically sent through PHP's htmlentities function to prevent XSS attacks. If you pass data from your Controller to a View with some HTML styling like: $first = "<b>Narendra Sisodia</b>"; And it is accessed, within Blade, with {{ $first }} then the output'll be: <b>Narendra Sisodia

How to Set Variables in a Laravel Blade Template

喜你入骨 提交于 2019-11-26 02:41:24
问题 I\'m reading the Laravel Blade documentation and I can\'t figure out how to assign variables inside a template for use later. I can\'t do {{ $old_section = \"whatever\" }} because that will echo \"whatever\" and I don\'t want that. I understand that I can do <?php $old_section = \"whatever\"; ?> , but that\'s not elegant. Is there a better, elegant way to do that in a Blade template? 回答1: It is discouraged to do in a view so there is no blade tag for it. If you do want to do this in your