i have time column in my data base . i need to defined field for this column.
this is my migration:
$table->date('date');
$table->time('time_begin');
$table->time('time_Enable');
this is my resource:
public function fields(Request $request)
{
return [
datetime::make('time_Enable'),
datetime::make('time_begin'),
];
}
i just need time not date and time
Impressively enough, Nova not only doesn't have a Time field but also doesn't support a time-only usage of DateTime field.
On the other side, Nova has plenty of third parties componentes that can be easily added via composer. I did look for some on Nova Packages and found two viable options: Laraning Time Field and Michielfb Time Field, they seem to be pretty good and open-source.
Nonetheless, they have relatively few stars on GitHub and a rather old latest version, which is not much of a problem for such a simples functionality, but I'd rather go with a native one, so here is how I implemented it:
Text::make('Duration')
->placeholder('##:##:##')
->rules('date_format:"H:i:s"')
->help('hh:mm:ss'),
So basically I used the Text field with a format validation. Also added the placeholder and help attributes to make it a bit more intuitive. It works well! and I'm using it with a time database field. Other colleges suggested using a masked component but it would also require a third party one and I didn't find a good option.
From the docs
You may customize the display format of your DateTime fields using the format method. The format must be a format supported by Moment.js:
DateTime::make('time_Enable')->format('H mm'),
DateTime::make('time_begin')->format('H mm'),
You can use the extraAttributes option with type key:
Text::make('time_begin')->withMeta(['extraAttributes' => ['type' => 'time']])
Related
Is it possible to create a one time link in Laravel? Once you open the link it expires?
I have created a Temporary Signed Link, but I can open it multiple times. How do I counter it?
There is this package that can help you
https://github.com/linkeys-app/signed-url/
This will generate a link valid for 24hours and for just one click .
$link = \Linkeys\UrlSigner\Facade\UrlSigner::generate('https://www.example.com/invitation', ['foo' => 'bar'], '+24 hours', 1);
The first time the link is clicked, the route will work like normal. The second time, since the link only has a single click, an exception will be thrown. Of course, passing null instead of '+24 hours' to the expiry parameter will create links of an indefinite lifetime.
There maybe a package that provides a functionality like this... always worth looking on Packagelist before building something rather generic like this from scratch. But, it's also not a hard one to build from scratch.
First you'll need database persistence, so create a model and a migration called UniqueLink. In the migration you should include a string field called "slug", a string field called path, and a timestamp field called "used_at."
Next create a controller with a single __invoke(string $slug) method. In the method look up the $link = UniqueLink::where('slug', $slug)->first(); Update the models' used_at parameter like so $link->update(['used_at' => Carbon::now()]);
Then return a redirect()->to($link->path);
Add a route to your routes file like this Route::get('/unique-link/{slug}', UniqueLinkController::class);
Now you'll just need to create a method to add these links to the db which create a slug (you could use a UUID from Str::uuid() or come up with something more custom) and a path that the link should take someone. Over all a pretty straight forward functionality.
You could track when the URL is visited at least once and mark it as such for the user if you really want to, or you could reduce the expiry down to a few mins.
URL::temporarySignedRoute( 'foobar', now()->addMinutes(2), ['user' => 100] );
I can't figure out how to set up the links. I have created a collection. I need an creator to be automatically specified in that record when adding a record to the collection. How do I do that?
I've faced this problem...
I found the solution in the documentation:
need to add
"populateCreatorFields": true
in the file (strapi v3) /api/your-type-name/models/your-type-name.settings.json
in options object
like:
...
"options": {
"increments": true,
"timestamps": true,
"draftAndPublish": true,
"populateCreatorFields": true
},
...
More information can be found at strapi documentation
Strapi does not support it by default. As mentioned in this form you can achieve it by editing the strapi's controller. But I will not recommend you to edit the strapi controller at all. Please avoid it.
There is a simple and better solution to this. You can achieve this by creating one to one relationship. Create an author table/collection. Make one to one relationship with your other collection. You can make it a required option as well. So whenever someone creates an entry they have to select an author from your already created collection of authors.
And now you can get relation in your API and use it wherever you want to.
As stated in my comment, Strapi (tested on v3) comes with a created by field. To ascertain the claim, the following steps can be followed;
Create a new content type. Here I am setting only one field, called test
Add an entry for that content type. Notice the last update and by field on the right.
Save and open the entry. The last update and by fields have been automatically populated.
i make one table for with some column with nullable.
i already tried with two different query. one using
Register_member::where('passport',$passport)->orWhere('adharcardnumber',$adharcardnumber)->get();
and second DB::table type query.
$row = Register_member::where('passport',$passport)->orWhere('adharcardnumber',$adharcardnumber)->get();
if (!empty($row))
{
return response()->json(["status"=>0, "message"=>"Adharcard or Paasport number already exit."]);
}
if (empty($row))
{
Register_member::insert(['first_name'=>request('first_name'), 'middle_name'=>request('middle_name'), 'last_name'=>request('last_name'), 'adharcardnumber'=>request('adharcardnumber'), 'ocipcinumber'=>request('ocipcinumber'), 'passport'=>request('passport'), 'birthday'=>request('birthday'),
'mobilecode'=>request('mobilecode'), 'mobilenumber'=>request('mobilenumber'), 'email'=>request('email'), 'address'=>request('address'), 'landmark'=>request('landmark'), 'area'=>request('area'),
'gender'=>request('gender'), 'pincode'=>request('pincode'), 'city_name'=>request('city_name'), 'state_id'=>request('state_id'), 'country_id'=>request('country_id'), 'sampraday'=>request('sampraday'), 'other'=>request('other'), 'sms'=>request('sms')]);
return response()->json(["status"=>1, "message"=>"Member register successful."]);
}
if adharcardnumber or passport number are exists in table, then nagetive response. if in both any one in unique then, insert data in table
Let me suggest you something which I think serve you as a good solution. You can use the unique with required and regex. In this way it will use the already recommended ways of Laravel which are the best.
As an example for your adhaar card,
the validation should look like this
$request->validate([
'adhaar ' =>['required','unique:users','regex:/\d{12}/'],
]);
where adhar is the filed name where adhaar number is entered. Be sure to use validator like this use Illuminate\Support\Facades\Validator;. Also $request is the instance of the Request.
Using the required prevent empty field submission and the regex will throw an error if the pattern is not matched completely. so I think it would be a better a way to handle the scenario.
the above solution will work in both adhaar and passport. But for the passport the regex will be different though.
Please note these are all demo examples, you might need to modify it according to your needs. I use https://www.phpliveregex.com/ for regex making and checking and it is good enough.
I hope you get an idea of how to begin but if you need more information then let me know in the comments.
I'm wondering if it's possible to describe a format, that an interface property should have. For example:
interface User {
age?: number,
name: string,
birthdate: string // should have format 'YYYY-MM-DD'
}
I read about decorators but it seems to only apply to classes, not interfaces.
I'm building an API with node/express and want to have input validation. So I'm considering Celebrate which can take joi type Schema to validate input. But I would like to use TypeScript instead to define my Schema / view model... As you see I try to use an Interface to define how the input of a given end point should look like:
age: number, optional
name: string
birthdate: string in format "YYYY-MM-DD"
Any hints and help much appreciated :)
Any hints and help much appreciated :)
First and foremost : you will have to write code for the validation. It will not happen magically.
Two approaches:
Out of band validation
You use validate(obj) => {errors?}. You create a validate function that takes and object and tells you any errors if any. You can write such a function yourself quite easily.
In band validation
Instead of {birthdate:string} you have something like {birthdate:FieldState<string>} where FieldState maintains validations and errors for a particular field. This is approach taken by https://formstate.github.io/#/ but you can easily create something similar yourself.
A note on validators
I like validators as simple (value) => error? (value to optional error) as they can be framework agnostic and used / reused to death. This is the validator used by formstate as well. Of course this is just my opinion and you can experiment with what suits your needs 🌹
In Django admin, one can set up a raw_id_fields in order to have a search widget instead of a select box. This is very neat to spare up a lot of database queries when the foreign key table is huge.
What is the equivalent in the Django Rest Framework browsable views?
Django Rest Framework 3 no longer supports widget attribute on serializer field. But to get your browsable API even usable, try changing style attribute to use 'base_template': 'input.html' as in following example:
class CustomerAddressSerializer(serializers.ModelSerializer):
customer = serializers.IntegerField(source='customer_id' style={'base_template': 'input.html', 'placeholder': "Customer ID"})
class Meta:
model = models.CustomerAddress
fields = ('id', 'customer', 'street', 'zip', 'city')
This way your huge select tag with thousands foreign key options will change to simple text input. For more info check docs at http://www.django-rest-framework.org/topics/browsable-api/#handling-choicefield-with-large-numbers-of-items
There's nothing to support this currently. I'm pretty sure that pull requests would be welcomed.
Seconding what Carlton says, although it'd be worth discussing in a ticket prior to taking a stab at the implementation.
Alternatively, you might want to take a look at using an autocomplete widget...
http://www.django-rest-framework.org/topics/browsable-api/#autocomplete