laravel

Limiting the result of nested relationship in Laravel

末鹿安然 提交于 2021-01-29 05:10:48
问题 I have a nested relationship that I want to set a condition and a limit. $data = Accommodation::with('accommodationFacilities', 'city') ->take(10) ->with('accommodationRooms.roomPricingHistory') ->limit(2) ->where('is_deleted', 0) ->paginate(10); Now I have a nested relation on line 2 that I want to limit this relation by: roomPricingHistory . The code limits the parent relation which is: accommodationRooms . Any idea how I can limit the child relation and how can I set an if for it so if a

Ignore the empty folder (403) and pass the URI to the Laravel controller with .htaccess

送分小仙女□ 提交于 2021-01-29 05:02:05
问题 I have a project with Laravel and inside the public folder ( httpdocs ) I have a folder /en/news , all works fine with the route /en/news but when I try to go to the /en I have a 403 error because it is a empty folder, the real problem there is that /en is a route in my Laravel project with the homepage of the web, so first executes de .htaccess and throw the 403. Is there any way to ignore this error for this specific folder/route ( /en ) or something like that? My .htaccess is the tipical

call javascript function outside foreach loop

强颜欢笑 提交于 2021-01-29 05:00:20
问题 I have a problem with my JavaScript function, when I put my script inside foreach loop like code I have below everything work fine, but I think it should be outside, so anyone can give me the advide to resolve this, I appreciate it @foreach($messages->reverse() as $message ) <ul class="id{{$message->id}}" data-id="{{$message->id}}"> <li class="message"> <div class="text {{ ($message->to!=Auth::user()->id)?'not_owner':'owner'}}"> {{$message->text}} </div><br> </li> <li class="message"> <div

How to add fields to a model via eloquent in Laravel?

不问归期 提交于 2021-01-29 04:56:44
问题 My question is if it is possible to add all the fields directly to a new model via Eloquent. I guess it would be something like php artisan make:model MyModel --fields=? However, I can't find anything related with that. Anyway, I have to generate a lot of model and any trick would be really appreciated. Thanks in advance 回答1: If you mean table's column by fields then: Firstly you don't need to define fields in modal. I mean in Laravel no need to define fields while creating model. Besides,

Ignore the empty folder (403) and pass the URI to the Laravel controller with .htaccess

让人想犯罪 __ 提交于 2021-01-29 04:52:55
问题 I have a project with Laravel and inside the public folder ( httpdocs ) I have a folder /en/news , all works fine with the route /en/news but when I try to go to the /en I have a 403 error because it is a empty folder, the real problem there is that /en is a route in my Laravel project with the homepage of the web, so first executes de .htaccess and throw the 403. Is there any way to ignore this error for this specific folder/route ( /en ) or something like that? My .htaccess is the tipical

Laravel Bulk Detach

ぐ巨炮叔叔 提交于 2021-01-29 04:41:33
问题 First, I use detach() in laravel with this approach and this is work! $student = \App\StudentRegistrars::withTrashed()->findOrFail($id); $student->father_registrars()->detach(); $student->mother_registrars()->detach(); But when I am trying to mass detach in laravel, I can't do that. $students = \App\StudentRegistrars::whereIn('id', $ids); $student->father_registrars()->detach(); $student->mother_registrars()->detach(); Any solution about this problem? 回答1: There's quite a few issues with your

Laravel: how to access a file in the local disk? - File does not exist

被刻印的时光 ゝ 提交于 2021-01-29 04:32:59
问题 I'm trying to edit an excel file after uploading it in laravel. the file is uploaded to local disk, so no one can access it from the public. Filesystems.php 'local' => [ 'driver' => 'local', 'root' => storage_path('app') Routes.php Route::get('test',function() { // Create new PHPExcel object $objPHPExcel = new PHPExcel(); $objPHPExcel = PHPExcel_IOFactory::load(Storage::disk('local')->url('margin/analyser/0IGkQQgmGXkHrV9ISnBTrGyZFUPfjz3cWJbLGbDN.xlsx')); $objPHPExcel->setActiveSheetIndex(0);

My form is not populating when there is some validation error in the input data. Laravel Collective

我与影子孤独终老i 提交于 2021-01-29 03:33:49
问题 Hope yo are all doing great. I am using Laravel 5.3 and a package LaravelCollective for form-model binding. I have subjects array that I want to validate and then store in database if there is no error in the input data. The following snippets show the partial view of form, other views, rules for validations and controller code. UserProfile.blade.php <!-- Panel that Adds the Subject - START --> <div class="col-md-12"> <div class="panel panel-default" id="add_Subject_panel"> <div class="panel

Laravel 5.7 on apache error Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length()

时光毁灭记忆、已成空白 提交于 2021-01-29 03:11:42
问题 I'm setting Laravel 5.7 on Apache 2.4 using PHP 7.1.26. I configured everything like documentations. But I'm getting the error below: Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length() I've already change PHP version to 7.2 and nothing. I've already copied the file libeay32.dll to Apache and nothing These are my modules in PHP [PHP Modules] bcmath calendar Core ctype curl date dom exif fileinfo filter gd gettext gmp hash iconv imap intl json ldap libxml mbstring

Laravel 5.2, Maximum function nesting level

烈酒焚心 提交于 2021-01-29 03:06:22
问题 Please, help me to find what is going on. I just set up a basic Laravel project. It's a new fresh Laravel project (5.2.29) This is route.php Route::get('/', 'TestController@index'); This is the test controller class TestController extends Controller { public function index() { return view('home'); } } The home.blade.php is the one that comes with a fresh Laravel installation, the one printing "Laravel 5". When I add the 'web' middleware, as following Route::group(['middleware' => ['web']],