Skip to content
Advertisement

Tag: php

localization FakerFactory does not work in laravel

I have a Post Model with these fields : Now I want to use laravel sedders and model factories to create fake fa_IR localized data and insert to posts table. For that I wrote this in database/factories/ModelFactory.php: Then I created a PostsTableSeeder class like this : And in AppServiceProvider.php added below codes to register function : But After running the

remove part of string after delimiter in php

I have seen other I have a string ” cccc cccc – fff” I need to return “cccc cccc” I don’t need to delimiter too I tried to echo the result of substr($mystring , 0, strpos($mystring , “-“)); but it return nothing I also tried resulted returned the main string and trash resulted nothing Update: i’m using wordpress and for

Laravel active menu item for url included parameters

I’m trying to set active class in my list item, but it doesn’t work. My code in blade: So, if I write: li class=”@if(getRouteName() == ‘site@index’){{ ‘active’ }}@endif” , it works nice, but in my case the problem is that I want to get ‘active’ class in foreach sites/’.$site->id.’/edit Many thanks. Answer Use is() method. For example:

Convert to Laravel exception?

Currently in a package, it has HttpException exception Is there a way to to convert it Laravel HttpResponseException uses without touching that exception from the package? Answer You can catch that exception and rethrow it. In your app/Exceptions/Handler.php file. Edit: I haven’t tested this but according to the exception class. You can pass a response as a parameter to the

PHP Iterate Multiple Children from XML

I’m trying to read an XML file in PHP which has multiple same-named nodes inside a parent. So far, I can read the first iteration of the XML node but then PHP moves to the next parent even though …

Advertisement