404 when removing parameter from request - laravel-8

below is put request in a function:
form.put(`/pos/${form.meal_type_id}/${form.user_id}/${form.group_id}/${form.date_served}/${form.adult}/${value}/false`)
Here is the route
Route::put('/pos/{meal_type_id}/{user_id}/{group_id}/{date_served}/{adult}/{meal_id}/{void}', [PosController::class, 'voidMeal'])
->middleware(['auth', 'verified'])->name('pos.voidTally');
And the function in the controller:
public function voidMeal($meal_type_id, $user, $group_id, $date_served, $adult, $meal_id, $void)
I no longer need to pass ${form.user_id}. But when I remove it from the request/route/controller I get a 404 error. Can anyone explain?
Here is the version without the user in case I'm making a mistake and not seeing it.
form.put(`/pos/${form.meal_type_id}/${form.group_id}/${form.date_served}/${form.adult}/${value}/false`)
Route::put('/pos/{meal_type_id}/{group_id}/{date_served}/{adult}/{meal_id}/{void}', [PosController::class, 'voidMeal'])
->middleware(['auth', 'verified'])->name('pos.voidTally');
public function voidMeal($meal_type_id, $group_id, $date_served, $adult, $meal_id, $void)
Please let me know if more info is needed. I don't think more info is needed, so if there is something else, that's probably it.

Related

How to make a post request using the gogearbox framework

I am currently stuck because I do not know how to complete my Post request for a project I am doing. I am using a framework called gearbox (I wanted to try something new). The main problem is I don't know how to bind the json to the new variable. So can anyone help me with this issue. For the info I can post the GitHub package. It's "github.com/gogearbox/gearbox" , Please help me.
I did try to look up the documentation,and I did try a few different functions but it didn't work so if anyone can help me please.
You should provide some code even if it doesn't work. It's usually a good starting point. This way we can avoid trying things you already tested out. I've briefly read the doc and didn't test the code below but you may try to look at the ParseBody function:
type Payload struct{
FirstName string `json:"firstname"`
LastName string `json:"lastname"`
}
requestHandler := func(ctx *fasthttp.RequestCtx) {
var payload *Payload
err := ctx.ParseBody(&payload)
if err!= nil {
ctx.Status(gearbox.StatusInternalServerError).SendString("Something went wrong when parsing your payload!")
}
// do something with your payload
}
reference here

Looking for a "legit" way to be able to log a Selector's function chain

I find that I often want to be able to log out what a Selector was looking for at various times during execution. I couldn't find a "legit" way to do this so I worked around it by creating the following function:
function printSelector(selector) {
console.log(selector[Object.getOwnPropertySymbols(selector)[0]].options.apiFnChain.join(""));
}
// And with this, if you have something like:
let mySelector = Selector('button').withText('foo').with({ visibilityCheck: true });
// You can run:
printSelector(mySelector);
// and get: Selector('button').withText('foo').with({ visibilityCheck: true })
My question is: is there some better way that doesn't require using the internal apiFnChain to find / log this info?
Thanks
TestCafe does not allow you to log Selectors if there were no Selector errors. However, the approach we use is similar to yours.
You can continue using your approach. However, please note that this is private API and it can be changed in the future.

ERR_UNSAFE_REDIRECT

I'm trying to get my server to redirect to another page in my 'public folder'. When I use:
response.redirect(path.join(__dirname, '../public/user_home.html'))
I get and error net::ERR_UNSAFE_REDIRECT
On the client side I have:
$.get( "/user_home", function( data ) {console.log(data)};
I can't find anything about this error. Am I going about this incorrectly?
Your public folder is already available if you have static middleware configured in your app.
app.use(express.static('public'))
You can use:
res.redirect("/user_home.html");
response.redirect(path.join(__dirname, '../public/user_home.html'),safe=true)

durandal event not working properly

I am using durandal to pass messages between view models. So i used below code to send message
return (datacontext.getData("Test, testData))
.then(app.trigger('FireEvent', `dataObsArray`))
.fail(queryFailed);
Then i use below code to retrieve message
app.on('FireEvent').then(function (data) {
testObsArray(data);
});
But when i put breakpoint in the app.on on this line testObsArray(data);
it doesnt stop there. The debugger stops on line app.on('FireEvent').then(function (data)
I dont get data. Why is it so? When i pass data to dataObsArray , there are 10 records.
I am not sure why i am not getting any data. Where i am wrong? I am really new to Durandal so extremely sorry if i am not able to explain this properly and do let me know if you need more clarification.
Your problem is here;
.then(app.trigger('FireEvent', `dataObsArray`))
The way that will resolve is to call app.trigger, get the result, and pass that as the next step in the chain to then(), which is unlikely to be what you want. You need to wrap that in an anonymous function so that then() can call it after the dataContext call.
return (datacontext.getData("Test, testData))
.then(function(data) {
app.trigger('FireEvent', data?) //This depends on what getData returns
})
.fail(queryFailed);

How do I utilize a named instance within the ObjectFactory.Initialize call for StructureMap?

I am trying to do the following bootstrapping:
x.For(Of IErrorLogger).Use(Of ErrorLogger.SQLErrorLogger)().
Ctor(Of IErrorLogger)("backupErrorLogger").Is(ObjectFactory.GetNamedInstance(Of IErrorLogger)("Disk"))
x.For(Of IErrorLogger).Add(
Function()
Return New ErrorLogger.DiskErrorLogger(
CreateErrorFileName(ServerMapPath(GetAppSetting("ErrorLogFolder"))))
End Function).Named("Disk")
But it shows this error:
StructureMap Exception Code: 200
Could not find an Instance named "Disk" for PluginType Logging.IErrorLogger
I sort of understand why this is happening.. the question is, how do I utilize a named instance within the registry? Maybe something like lazy initialization for the ctor argument for the SQLErrorLogger? I am not sure how to make it happen.
Thanks in advance for any help you can provide.
I found the correct way to do it in the latest version (2.6.1) of StructureMap:
x.For(Of IErrorLogger).Use(Of ErrorLogger.SQLErrorLogger)().
Ctor(Of IErrorLogger)("backupErrorLogger").Is(
Function(c) c.ConstructedBy(Function() ObjectFactory.GetNamedInstance(Of IErrorLogger)("Disk"))
)
x.For(Of IErrorLogger).Add(Function() _
New ErrorLogger.DiskErrorLogger(
CreateErrorFileName(ServerMapPath(GetAppSetting("ErrorLogFolder"))))
).Named("Disk")
Notice for the Is method of Ctor, we need to provide a func(IContext), and use the IContext.ConstructedBy(Func()) to call ObjectFactory.Get... to successfully register the IErrorLogger in this case.
This is the only way to do it as far as I know. The other Icontext methods such as IsThis and Instance will only work with already registered type.
Your problem is that you are trying to access the Container before it's configured. In order to make structuremap evaluate the object resolution after the configuration you need to provide a lambda to the Is function. The lambda will be evaluated when trying to resolve the type registered.
x.[For](Of ILogger)().Add(Of SqlLogger)().Ctor(Of ILogger)("backupErrorLogger")_
.[Is](Function(context) context.GetInstance(Of ILogger)("Disk"))
x.[For](Of ILogger)().Add(Of DiskLogger)().Ctor(Of String)("errorFileName")_
.[Is](CreateErrorFileName(ServerMapPath(GetAppSetting("ErrorLogFolder"))))_
.Named("Disk")
Disclaimer: I'm not completely up-to-date with the lambda syntax in VB.NET, but I hope I got it right.
Edit:
The working C# version of this I tried myself before posting was this:
ObjectFactory.Initialize(i =>
{
i.For<ILogger>().Add<SqlLogger>()
.Ctor<ILogger>("backup").Is(
c => c.GetInstance<ILogger>("disk"))
.Named("sql");
i.For<ILogger>().Add<DiskLogger>().Named("disk");
});
var logger = ObjectFactory.GetNamedInstance<ILogger>("sql");