laravel-4

Str::slug alternative for hindi and arabic strings?

試著忘記壹切 提交于 2019-12-03 16:00:14
I use Str::slug to generate friendly URL's, however Str::slug() method returns null on arabic and hindi strings. Probably chinese, japanese, korean and those charsets too. For example: return Str::slug('मनोरंजन'); //null How can I solve this issue efficiently? I have faced this problem when I was working with Arabic language, so I've made the following function which solved the problem for me. function make_slug($string = null, $separator = "-") { if (is_null($string)) { return ""; } // Remove spaces from the beginning and from the end of the string $string = trim($string); // Lower case

Laravel: Save Base64 .png file to public folder from controller

怎甘沉沦 提交于 2019-12-03 15:53:47
问题 I send a png image file to controller in base64 via Ajax. I've already test and sure that controller has received id but still can't save it to public folder. Here is my controller public function postTest() { $data = Input::all(); //get the base-64 from data $base64_str = substr($data->base64_image, strpos($data->base64_image, ",")+1); //decode base64 string $image = base64_decode($base64_str); $png_url = "product-".time().".png"; $path = public_path('img/designs/' . $png_url); Image::make(

Check if name is unique among non-deleted items with laravel validation

╄→尐↘猪︶ㄣ 提交于 2019-12-03 15:46:45
问题 I have a simple form which posts to a controller which checks if a name for an item is already taken for a particular project. If it is, then it returns an error. This is the code I'm using for that: 'name' => 'required|min:1|unique:versions,name,NULL,id,project_id,'.$project->id, The problem I've run into is that instead of a hard delete, I'm using a soft delete to remove them from the database, meaning that, for example, 'Test' can only be used as the name once, even after it's been deleted

Why soft deleted entities appear in query results?

拈花ヽ惹草 提交于 2019-12-03 15:43:59
问题 I am trying to implement soft deleting concept. Here is my object: class Post extends Eloquent { /** * The database table used by the model. * * @var string */ protected $table = 'posts'; protected $softDelete = true; ... Soft delete is on. Now, if I 'delete' a post, it gets a 'deleted_at' timestamp: The problem is, when I search or just use all() to display the posts, the soft deleted items appears there. What is wrong? 回答1: The soft deleting feature works when using Eloquent. If you are

Affect on security of Laravel 5 when change folder structure to remove public folder

爷,独闯天下 提交于 2019-12-03 15:43:38
I'm new in Laravel 5. I found this Laravel 5 - Remove public from URL on Stack Overflow to remove public folder from my Laravel 5 App. Only I have a question about the security. When I am removing public from URL, then I have to change the basic folder structure of Laravel 5. Yes, it's working fine without the public from the URL. But what's about the security of Laravel, because I am changing the default folder structure? Is it secure to use? You should be pointing your Apache host root to the $LARAVEL_PATH/public directory instead of $LARAVEL_PATH . The point of having sub directory for www

Laravel sort Relationship

做~自己de王妃 提交于 2019-12-03 15:24:05
How can I sort my result with related tables? I have this tables: Clients and Managers (users table) Client.php <?php class Client extends Eloquent { protected $table = 'clients'; public function Manager(){ return $this->belongsTo('User','manager','id'); } public function Transaction(){ return $this->hasMany('ClientTransaction','client','id'); } } Users.php (default Laravel's model) My question is how can I query table clients to be sorted by Manager's name. Here is my code so far: public function getClients() { // Sorting preparations $allowed = array('name','contact','money'); $sort = in

How does Laravel 4 load deferred provider?

我是研究僧i 提交于 2019-12-03 15:18:03
问题 I need to deeply understand laravel. I have to explain everything to my dev team since we are starting to use laravel. Please correct this if it is wrong: When laravel start, due to increasing performance, it split services provider to 'eager' and 'deferred', then it register all 'eager' provider, but not 'deferred'. My question: Each time we use deferred services, e.g: $validator = Validator::make( //.. ); How does laravel load and register that class/services ? I just find this probably

Laravel 4 - Inserting multiple records when using the hasMany relationship

谁说我不能喝 提交于 2019-12-03 15:14:59
Still finding my feet with Laravel 4 and I'm a little unsure as to why this isn't working. In L3 I was able to insert multiple records to a table like so... $comments = array( array('message' => 'A new comment.'), array('message' => 'A second comment.'), ); $post = Post::find(1); $post->comments()->save($comments); However when I try to do similar now either the records are inserted without the foreign key, like so... $comments = array( array('message' => 'A new comment.'), array('message' => 'A second comment.'), ); $post = Post::first(); $post->comments()->insert($comments); Or (and after

Laravel PDOException SQLSTATE[HY000] [1049] Unknown database 'forge'

試著忘記壹切 提交于 2019-12-03 15:04:24
问题 I am using Laravel to connect to MySQL database. I got this exception: PDOException SQLSTATE[HY000] [1049] Unknown database 'forge' and this is my config.database.php 'mysql' => array( 'driver' => 'mysql', 'host' => 'localhost', 'database' => 'laravel', 'username' => 'Anastasie', 'password' => 'A@Laurent', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ), why is the error referring to PDO database? and why the forge database name? I have already changed it. Should I do

How specifically does Laravel build and check a CSRF token?

筅森魡賤 提交于 2019-12-03 15:03:51
问题 I'm using Laravel's CSRF protection on my public site. However since Laravel uses a session to maintain this, I'm worried that a user might walk away from their computer and return to a page they have previously left open, only to find ajax requests don't work. The ajax requests don't work because the session has timed out (and the token no longer validates?). If these users were "logged in" users, then I could simply redirect them back to the login page. Since they are public users, then the