Last active
May 16, 2024 15:04
-
-
Save MrShennawy/024a25bca2fd4a4f9757aba42c538717 to your computer and use it in GitHub Desktop.
now you can query by regexp in laravel !! بالعربى إزاى تعمل بحث بالألف همزه ومن غير وهكذا ة ه وال ي وي ..... إلخ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//الملف ده اللى بيكون موجود فيه الدوال المساعده للشغل وغالبا بيكون مساره كالتالى | |
// app/helper/help.php | |
// ملحوظه (الملف ده انت اللى بتعمله عشان تحط جوا الفنكشنز اللى هتساعدك فى شغلك )0 | |
#================ search at sql text to regx ===================================== | |
function sql_text_to_regx($string){ | |
$alamat = array("+","=","-","_",")","(","*","&","^","%","$","#","@","!","/","\\","|",">","<","?","؟"); | |
$alamat_change = ""; | |
$alef = array("ا","أ","آ","إ"); | |
$alef_change = "@@@"; | |
$alef_last_change = "(ا|أ|آ|إ)"; | |
$yeh = array("ى","ي"); | |
$yeh_change = "(ي|ى)"; | |
$teh = array("ة","ه"); | |
$teh_change = "(ة|ه)"; | |
$abd = array("عبد {$alef_change}ل","عبد{$alef_change}ل"); | |
$abd_change = "(عبدال|عبد ال)"; | |
$alfLam = array("{$alef_change}ل{$alef_change}","{$alef_change}"); | |
$alfLam_change = "(ا|أ|آ|إلا|أ|آ|إ|ا|أ|آ|إ)"; | |
$all_changes = array($alamat, $alef ,$yeh ,$teh ,$abd ,$alfLam ,$alef_change ); | |
$replaces = array($alamat_change,$alef_change,$yeh_change,$teh_change,$abd_change,$alfLam_change,$alef_last_change ); | |
$id = 0; | |
foreach ($all_changes as $change) { | |
$string = str_replace($change,$replaces[$id],$string); | |
$id++; | |
} | |
return $string; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use Illuminate\Http\Request; | |
use App\Area; | |
use DB; | |
class AreaController extends Controller | |
{ | |
// طبعا ده الكنترولر اللى هيتنفذ فيه الشغل | |
public function test($text){ | |
$areas = Area::whereRaw('name REGEXP "'.sql_text_to_regx($text).'"')->get(); | |
return view('test',compact('areas')); | |
} | |
// اللى مهمتها تحويل الحروف اللى حددناها لصيغة الرجيكس ب sql_text_to_regx() هنا استدعينا الفنكشن | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
|-------------------------------------------------------------------------- | |
| Web Routes -------------------------------------------------------------- | |
|-------------------------------------------------------------------------- | |
| | |
| Here is where you can register web routes for your application. These | |
| routes are loaded by the RouteServiceProvider within a group which | |
| contains the "web" middleware group. Now create something great! | |
| | |
*/ | |
#================================================================================= | |
#============================ test Area ========================================== | |
route::get('/test/{text}','AreaController@test'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
use Illuminate\Database\Eloquent\Model; | |
// الموديل بالمره يلا هه :D | |
class Area extends Model | |
{ | |
protected $table = 'areas'; | |
public $timestamps = true; | |
protected $fillable = ['parent_id','name']; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//ده الفيو بتاعنا | |
dd($areas); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
المنشور مفيد جدا جدا سلمت يداك..