can we combine laravel language files like validation.php to json? - laravel

We can use json language files like ja.json from Laravel 5.4.
But i have still php language files like validation.php.
Is there a way to put inside json language files to share front end?

I suggest in your controller you do something like:
https://laravel.com/docs/5.4/localization#retrieving-translation-strings
public function convertLangToJson(){
$lang = __('languagefilename');
return response()->json($lang);
}

Related

Is there something similar to Twig filters that I can use in Laravel Blade

Twig has this awesome feature called Twig Filters which allow you to change the variables that you send to your view, from within the view without messing with the data model.
{ variable_name | filter_name }
This makes it super-duper readable and clean. Filters can be lowercase, encoding, raw text or you can build your own.
Question is simple: I really miss this kind of functionality, what's the best way to implement something like this in Laravel using Blade?
as i know Blade don't offer this functionality of filters, but u can create a helper file that can has many functions helper and every function has her logic.
in this link u can find how to create a helper file with functions and call them inside ur blade file tutorial how to create helper function

Creating a new page in Laravel

I'm trying to create a new page in Laravel and I'm not sure what to do in the context of the Laravel framework.
If it was just html, then you just create a new html file. In Laravel, what are all the things you need to do when creating a new page?
The easiest way in Laravel is to define a route closure, and return a view from it.
In your routes/web.php file:
Route::get('/my-page', function () {
return view('my-page');
});
Then in resources/views you create a file called my-page.php, or if you want to use Laravel's Blade syntax (you probably do) call it my-page.blade.php.
Edit: there's now an even easier way to to it. Also in routes/web.php:
Route::view('/my-page', 'my-page');
This will do exactly the same thing as the previous example, without the need for a closure and explicitly calling view().
There are two locations to add New Page to your Laravel project:
You have to create an additional route in YOURAPP>routes>web.php file.
You have to add PHP file with that name to YOURAPP>resources>views folder. If you want to use BLADE for your project, than you should put name_of_page.blade.php. And you should concider it as a must at the very beginning :).
Now, in routes you should be able to add only first part of the file rather than .blade.php. For example: about.blade.php, you can put in route only about
It should work out of the box :).
You can also try this in routes/web.php
Route::get('/my-page', function () {
return view('my-page');
})->name('my-page');

How to make url from a string in Laravel?

Does a Laravel has an included function to convert a string to an url? Or should I use some standart PHP libraries? But with standard library there is a problem with duplicating url... So there should be a script for every model..?
Example:
'Apple Cake'=>'apple-cake'
If you’re wanting to convert a title-case word to a URL-friendly string, then you can use the Str::slug() method:
use Illuminate\Support\Str;
$slug = Str::slug('Apple Cake'); // apple-cake
I also have found https://github.com/cviebrock/eloquent-sluggable slug maker for Laravel, if someone will have the same problem

Laravel 5 includes without blade

I would like to include a file on my index page. In php I use something like include('include/header.php');
or in larvel 4 I used include(app_path().'/views/includes/header.php');
My question is...How is it done in Laravel 5 since the whole framework has changed folder structures and what not? It seems that app_path() is not longer valid. Also, I do not want to leverage blade syntax. Does anyone have an idea on this?
Use base_path because the views are not outside off the app directory. Also you can pass the path to the function, no need for string concatenation
include(base_path('resources/views/includes/header.php'));
Try it like this:
include(app_path().'/../resources/views/includes/header.php');

How to fetch data from controller to views in CakePHP or Yii

How to fetch data from controller to views in CakePHP or Yii but not embed PHP code in views file (view is html file).
it similar Template Parser Class in Codeigniter:
https://www.codeigniter.com/user_guide/libraries/parser.html
You will need to load the data in the action controller by calling one of the model functions like findAll()
here is an example, assume we have a User model, and you need to pull out all the data and render them at view file:
public function actionIndex(){
$model = Users::model()->findAll();
$this->render('index', array('model' => model));
//the model variable will be defined in the index.php
//file and will have a value as assigned in the array
//index.php file should be located under /views/users/index.php
}
Now in index.php file do a var_dump and see what results you got.
I don't see the problem with embedding php into HTML. But if you really don't want to do it, you can use CakePHP with a template library like Mustache.
Check this: https://github.com/electblake/CakePHP-Mustache-Plugin

Resources