-
-
Save IsmailShurrab/3eebf08b69e7c9b13405ed4f8036dabc to your computer and use it in GitHub Desktop.
now you can query by regexp in laravel !! بالعربى إزاى تعمل بحث بالألف همزه ومن غير وهكذا ة ه وال ي وي ..... إلخ
This file contains 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 = "(عبدال|عبد ال)"; | |
$all_changes = array($alamat, $alef ,$yeh ,$teh ,$abd ,$alef_change ); | |
$replaces = array($alamat_change,$alef_change,$yeh_change,$teh_change,$abd_change,$alef_last_change ); | |
$id = 0; | |
foreach ($all_changes as $change) { | |
$string = str_replace($change,$replaces[$id],$string); | |
$id++; | |
} | |
return $string; | |
} |
This file contains 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 = DB::select('select * from areas where name REGEXP :sreachText', ['sreachText' => sql_text_to_regx($text)]); | |
return view('test',compact('areas')); | |
} | |
// اللى مهمتها تحويل الحروف اللى حددناها لصيغة الرجيكس ب sql_text_to_regx() هنا استدعينا الفنكشن | |
} |
This file contains 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 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 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