I know that I can use mocha.parallel to execute my it() tests in parallel, but how can I execute each describe() block in parallel while executing each it() test within the describe() block sequentially?
For example, suppose that I have a series of tests that copies a file from point A to B, then B to C, then C to D so that each test is dependent upon the last and must be executed sequentially:
describe('file transfer test', function () {
it('copies file from A to B', function (done) {...});
it('copies file from B to C', function (done) {...});
it('copies file from C to D', function (done) {...});
});
Now suppose that I want to execute this test suite 3 times in parallel with 3 different files of vastly varying sizes:
// in parallel
describe('file transfer test 1', function () {
it('copies file 1 from A to B', function (done) {...});
it('copies file 1 from B to C', function (done) {...});
it('copies file 1 from C to D', function (done) {...});
});
describe('file transfer test 2', function () {
it('copies file 2 from A to B', function (done) {...});
it('copies file 2 from B to C', function (done) {...});
it('copies file 2 from C to D', function (done) {...});
});
describe('file transfer test 3', function () {
it('copies file 3 from A to B', function (done) {...});
it('copies file 3 from B to C', function (done) {...});
it('copies file 3 from C to D', function (done) {...});
});
How can I achieve this?
Related
I want to filter the data in my table. I want if I select the first box it will show the data accordingly and if I select the second box it will show the data accordingly but the problem is that if I select the first box here the data does not show then the second box has to be selected.
Here is my controller code
public function UpazilaWiseReportShow(Request $request){
$data = [];
$data['report_data'] = Report::distric()->status(1)
->where('upazila_id',$request->upazila_id)->where('fiscal_year', $request->fiscal_year)
->get();
return view('adc.reports.upazilla-wise-data', $data);
}
here is my view code
<script>
$(document).ready(function() {
$('#upazila_id').on('change', function() {
getFilterData();
});
$('#fiscal_year').on('change', function (e) {
getFilterData();
});
});
function getFilterData() {
$.ajax({
type: "GET",
data: {
upazila_id: $("[name=upazila_id]").val(),
fiscal_year: $("[name=fiscal_year]").val()
},
url: "{{url('adc/upazila-wise-report')}}",
success:function(data) {
$("#report_data_table").html(data);
}
});
}
</script>
You should check if your $request has your needed fields. So you have to check if your request has these fields. You can use when method for it.
With the code below, you can either select fiscal year or upazila_id or both.
$data['report_data'] = Report::distric()
->status(1)
->when(
isset($request->upazila_id),
function ($query) use ($request) {
$query->where('upazila_id', $request->upazila_id);
}
)
->when(
isset($request->fiscal_year),
function ($query) use ($request) {
$query->where('fiscal_year', $request->fiscal_year);
}
)
->get();
I would like to create a route group in Laravel with a variable as a prefix. I need to set certain conditions too. How to do it properly?
I was following docs: https://laravel.com/docs/8.x/routing#route-group-prefixes but there are only general examples.
This code should create 2 routes: /{hl}/test-1 and /{hl}/test-2 where {hl} is limited to (en|pl), but it gives an error: "Call to a member function where() on null"
Route::prefix('/{hl}')->group(function ($hl) {
Route::get('/test-1', function () {
return 'OK-1';
});
Route::get('/test-2', function () {
return 'OK-2';
});
})->where('hl','(en|pl)');
The group call doesn't return anything so there is nothing to chain onto. If you make the where call before the call to group, similarly to how you are calling prefix, it will build up these attributes then when you call group it will cascade this onto the routes in the group:
Route::prefix('{hl}')->where(['h1' => '(en|pl)'])->group(function () {
Route::get('test-1', function () {
return 'OK-1';
});
Route::get('test-2', function () {
return 'OK-2';
});
});
By analogy with this answer:
Route::group([
'prefix' => '{hl}',
'where' => ['hl' => '(en|pl)']
], function ($hl) {
Route::get('/test-1', function () {
return 'OK-1';
});
Route::get('/test-2', function () {
return 'OK-2';
});
});
Does this solve your problem?
I'm trying to use the id from my show function in my controller,
My controller works correctly with this $id
public function show($id)
{
$DigestReport = Meo::find($id);
return view('digest-report.show', ['DigestReport' => $DigestReport]);
}
I'm trying to use the same $id for another function
public function getMailRecipients($id){
$meoId = Meo::find(id);
$mailRecipients = $this->meoRepository->getMailRecipients($meoId);
return DataTables::of($mailRecipients)->make();
}
but I get the following error
Too few arguments to function
DigestReportController::getMailRecipients(), 0 passed on line 54 and
exactly 1 expected
How can I fix it?
added: if necessary, this is my repository
public function getMailRecipients($meoId){
return DB::table('mail_recipients')->where('meo_id', '=', $meoId)->select('id', 'name', 'email')->get();
My api.php where are my stored routes
Route::get('/digest-report/mail-recipients', 'DigestReportController#getMailRecipients')->name('digest-report.mail-recipients');
My view where I'm using this controller, is for make a datatable
$(document).ready(function () {
$('#mail-recipient-table').DataTable({
"processing": true,
"serverSide": true,
"ajax": '{{route('digest-report.mail-recipients')}}',
"columns": [{data:'id'},{data: 'name'},{data: 'email'}]
});
})
Thanks
Ok you have two ways to do this
in your web.php you will update your route to be
Route::get('/digest-report/mail-recipients/{id}', 'DigestReportController#getMailRecipients')->name('digest-report.mail-recipients');
then you javascript code will be
$(document).ready(function () {
$('#mail-recipient-table').DataTable({
"processing": true,
"serverSide": true,
"ajax": '{{route('digest-report.mail-recipients', $DigestReport->id)}}',
"columns": [{data:'id'},{data: 'name'},{data: 'email'}]
});
})
in you controller you will update getMailRecipients
public function getMailRecipients(Request $request){
$meoId = Meo::find($request->id); // or using helper request('id') function
$mailRecipients = $this->meoRepository->getMailRecipients($meoId);
return DataTables::of($mailRecipients)->make();
}
and your javascript code will be the same
I have 2 queries like this:
$expiresAt = Carbon::now()->addMinutes(10);
$thumbnails = Cache::remember('entities-thumbnails-'.$entity_id, $expiresAt, function () use ($entity_id) {
return Images::where(['entity_id' => $entity_id, 'image_style' => 'thumbnail'])
->select('path AS thumbnail', 'width As thumbnailWidth', 'height As thumbnailHeight');
});
$largeImages = Cache::remember('entities-largeImages-'.$entity_id, $expiresAt, function () use ($entity_id) {
return Images::where(['entity_id' => $entity_id, 'image_style' => 'large'])
->select('path AS src')
->union($thumbnails)
->get();
});
What I want to do is not execute them seperately but as one query. Overall there will be 4 queries therefore instead of doing 4 I want to do one, is that possible? How does union work exactly?
Storing whole plain results in PHP variable then let PHP do such filtering would be better in my point of view. As an example
$images = Image::where('entity_id', $entity_id)->get();
$thumbnails = Cache::remember('entities-thumbnails-'.$entity_id, $expiresAt, function () use ($images) {
return $images->filter(function ($image) {
return $image->image_style === 'thumbnail';
});
});
$largeImages = Cache::remember('entities-largeImages-'.$entity_id, $expiresAt, function () use ($images) {
return $images->filter(function ($image) {
return $image->image_style === 'large';
});
});
You might call UNION is literally the same as JOIN. But, it does combining results set into one in an operation rather than relate them horizontally. Still, both need to be separated by PHP, as each row recorded are united into one collection.
I'm assuming you still need to make aliases for specified columns. Fortunately, Laravel is able to do that out of the box.
$thumbnails = Cache::remember('entities-thumbnails-'.$entity_id, $expiresAt, function () use ($images) {
return $images->filter(function ($image) {
if ($image->image_style === 'thumbnail') {
$image->setAttribute('thumbnail', $image->path);
$image->setAttribute('thumbnailWidth', $image->width);
$image->setAttribute('thumbnailHeight', $image->height);
return true;
}
return false;
});
});
$largeImages = Cache::remember('entities-largeImages-'.$entity_id, $expiresAt, function () use ($images) {
return $images->filter(function ($image) {
if ($image->image_style === 'large') {
$image->setAttribute('src', $image->path);
return true;
}
return false;
});
});
The basic idea is to work like a sub-domain architecture, but the user account will come after website's name.
I have a web service that is called myService.com.
I will have users like Paul, Anne, Jhon.
I want Laravel to be able to create home pages for Paul, Anne and Jhon like this:
myService.com/Paul = > Should redirects to Paul home page
myService.com/Anne = > Should redirects to Anne home page
myService.com/Jhon = > Should redirects to Jhon home page
but myService.com has its own home page and others pages too. I do like this:
Route::get('/', function () {
return view('home');//myService.com HOME page
});
Route::group(['prefix'=>'videos'], function (){
Route::get('/', function () {
return "all videos";
});
Route::get('/{id}', function ($id) {
return "Video => $id";
});
});
Route::group(['prefix'=>'articles'], function (){
Route::get('/', function () {
return "all articles";
});
Route::get('/{id}', function ($id) {
return "Article => $id";
});
});
For the users I will have almost the same URL structure:
myService.com/Paul
myService.com/Paul/videos
myService.com/Paul/videos/id
myService.com/Paul/articles
myService.com/Paul/articles/id
myService.com/Paul2
myService.com/Paul2/videos
myService.com/Paul2/videos/id
myService.com/Paul2/articles
myService.com/Paul2/articles/id
Since I will have unlimited users account I dont know how to design the Route structure for this scenario.
Is It should be like this?
Route::group(['prefix'=>'account'], function (){
Route::get('/', function ($account) {
return "user $account home page";//Ex myService.com/Paul
});
Route::group(['prefix'=>'videos'], function (){
Route::get('/', function () {
return "user account - all videos";//Ex myService.com/Paul/videos
});
Route::get('/{id}', function ($id) {
return "user account video => $id";//Ex myService.com/Paul/videos/id
});
});
Route::group(['prefix'=>'articles'], function (){
Route::get('/', function () {
return "user account - all articles";//Ex myService.com/Paul/articles
});
Route::get('/{id}', function ($id) {
return "user account articles => $id";//Ex myService.com/Paul/articles/id
});
});
});
This is what I did so far, but I dont know if it is a good approach. It is correct?
Define that group at the end of your routes so the other routes will have precedence. Then you can use slug for username (or whatever you are using)
Route::group(['prefix' => '{username}'], function(){
Route::group(['prefix' => 'videos'], function(){
...
});
});
But this groupe is more likely to try and pick up all your 404. Maybe you can add extra constraint
Route::group(['prefix' => '{username}'], function(){
...
})->where('username', '[A-Za-z]+');