public function rules()
{
return [
'title' => 'required|string|max:255,unique:categories,title',
'slug' => 'required|string|max:255,unique:categories,slug',
];
}
public function up()
{
Schema::create('categories', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->string('slug');
$table->timestamps();
});
}
<?php
namespace App\Http\Requests\Category;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;
class StoreRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules()
{
return [
'title' => 'required|string|max:255,unique:categories',
'slug' => 'required|string|max:255,unique:categories',
];
}
protected function failedValidation(Validator $validator)
{
throw new HttpResponseException(response()->json(
[
'errors' => $validator->errors(),
'status' => true
],
400
));
}
}
print(f"full_path: {full_path}")
return full_path
group_path = getGroupPathById(file_path, group_id)
new_tab = newTab(new_group_name)
group_path.append(new_tab)
new_group = newGroup(new_group_name)
group_path.append(new_group)
function eventsApiPosts()
{
register_rest_route('events/v1', 'posts', [
'methods' => WP_REST_SERVER::READABLE,
'callback' => 'eventsApiPostsFunc',
]);
}
add_action('rest_api_init', 'eventsApiPosts');
function eventsApiPostsFunc($data)
{
$term_slug = $data['term_slug'] ?? null;
$date = $data['date'];
$now = date('Y-m-d');
$current_page = $data['current_page'];
$lang = $data['lang'];
if ($date) {
if ($date === 'coming-soon') {
$meta_query = array(
array(
'key' => 'loop_event_date',
'value' => $now,
'compare' => '>',
'type' => 'DATE'
)
);
} else if ($date === 'past-events') {
$meta_query = array(
array(
'key' => 'loop_event_date',
'value' => $now,
'compare' => '<',
'type' => 'DATE'
)
);
} else {
$meta_query = array(
array(
'key' => 'loop_event_date',
'value' => $date,
'compare' => 'LIKE'
)
);
}
}
$tax_query = [];
if ($term_slug) {
$tax_query = array(
array(
'taxonomy' => 'events_category',
'field' => 'slug',
'terms' => [$term_slug],
)
);
}
$post_type = 'events';
$posts_per_page = 3;
$offset = ($current_page * $posts_per_page) - $posts_per_page;
$post_events = new WP_Query(array(
'post_type' => $post_type,
'posts_per_page' => $posts_per_page,
'offset' => $offset,
'tax_query' => $tax_query,
'meta_query' => $meta_query,
// 'orderby' => 'meta_value', // Order by meta value as numeric
// 'meta_key' => 'featured', // Meta key for sorting
// 'meta_type' => 'DATE', // Meta type
// 'order' => 'DESC',
));
$total_posts = $post_events->found_posts;
$pages = ceil($total_posts / $posts_per_page);
$events_array = $post_events->get_posts();
$events_array = array_map(function ($event) use ($lang) {
$id = $event->ID;
$title = get_the_title($id);
$term = get_the_terms($id, 'events_category')[0];
if ($lang === 'ro') {
$location = get_field('title_ro', $term);
} else {
$location = $term->name;
}
$loop = get_field('loop', $id);
$event_date = $loop['event_date'];
$short_description = $loop['short_description'];
$image = get_the_post_thumbnail_url($id);
return [
'id' => $id,
'title' => $title,
'location' => $location,
'event_date' => $event_date,
'featured' => get_field('featured', $id),
'short_description' => $short_description,
'image' => $image,
'lang' => $lang,
'term_name' => $term->name,
'permalink' => get_the_permalink($id),
];
}, $events_array);
$count = count($events_array);
return [
'lang' => $lang,
'total' => $total_posts,
'count' => $count,
'pages' => $pages,
'current_page' => $current_page,
'events' => $events_array,
'offset' => $offset,
'current_page' => $current_page,
'posts_per_page' => $posts_per_page,
];
}