File manager - Edit - /home/asiatechinc/public_html/asiatech-websites/demo/Dynast/app/Http/Controllers/MetaController.php
Back
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Meta; // Ensure your Meta model is correctly imported use Illuminate\Validation\Rule; class MetaController extends Controller { /** * Display a listing of the meta records. * Used for the administration table view. */ public function index() { // Paginate the results for easier browsing in the admin panel $metas = Meta::orderBy('page_path')->paginate(15); return view('Dashboard.Pages.meta.index', compact('metas')); } /** * Show the form for creating a new meta record. */ public function create() { return view('Dashboard.Pages.meta.create'); } /** * Store a newly created meta record in the database. */ public function store(Request $request) { $validated = $request->validate([ // CORE FIELDS 'page_path' => ['required', 'string', 'max:255', 'unique:metas,page_path'], 'robots' => ['required', 'string', 'max:100'], 'title' => ['nullable', 'string', 'max:255'], 'description' => ['nullable', 'string'], 'keywords' => ['nullable', 'string', 'max:255'], 'canonical_url' => ['nullable', 'url', 'max:255'], // Added URL validation // OPEN GRAPH FIELDS 'og_title' => ['nullable', 'string', 'max:255'], 'og_description' => ['nullable', 'string'], 'og_image' => ['nullable', 'url', 'max:255'], // Added URL validation 'og_site_name' => ['nullable', 'string', 'max:100'], 'og_type' => ['nullable', 'string', 'max:50'], 'og_locale' => ['nullable', 'string', 'max:20'], // TWITTER CARD FIELDS 'twitter_card' => ['nullable', 'string', 'max:50'], 'twitter_site' => ['nullable', 'string', 'max:100'], 'twitter_title' => ['nullable', 'string', 'max:255'], 'twitter_description' => ['nullable', 'string'], 'twitter_image' => ['nullable', 'url', 'max:255'], // Added URL validation // HREFLANG FIELD 'alternate_links' => ['nullable', 'json'], // Ensure the input is valid JSON ]); // Clean up the page_path: ensure it starts with '/' $validated['page_path'] = '/' . ltrim($validated['page_path'], '/'); Meta::create($validated); return redirect()->route('meta.index') ->with('success', 'Meta record created successfully for ' . $validated['page_path'] . '.'); } /** * Show the form for editing the specified meta record. */ public function edit(Meta $meta) { // The Meta model is automatically retrieved by its ID (Route Model Binding) return view('Dashboard.Pages.meta.edit', compact('meta')); } /** * Update the specified meta record in the database. */ public function update(Request $request, Meta $meta) { $validated = $request->validate([ // CORE FIELDS // Rule::unique checks for uniqueness but ignores the current record's ID 'page_path' => ['required', 'string', 'max:255', Rule::unique('metas')->ignore($meta->id)], 'robots' => ['required', 'string', 'max:100'], 'title' => ['nullable', 'string', 'max:255'], 'description' => ['nullable', 'string'], 'keywords' => ['nullable', 'string', 'max:255'], 'canonical_url' => ['nullable', 'url', 'max:255'], // URL validation // OPEN GRAPH FIELDS 'og_title' => ['nullable', 'string', 'max:255'], 'og_description' => ['nullable', 'string'], 'og_image' => ['nullable', 'url', 'max:255'], // URL validation 'og_site_name' => ['nullable', 'string', 'max:100'], 'og_type' => ['nullable', 'string', 'max:50'], 'og_locale' => ['nullable', 'string', 'max:20'], // TWITTER CARD FIELDS 'twitter_card' => ['nullable', 'string', 'max:50'], 'twitter_site' => ['nullable', 'string', 'max:100'], 'twitter_title' => ['nullable', 'string', 'max:255'], 'twitter_description' => ['nullable', 'string'], 'twitter_image' => ['nullable', 'url', 'max:255'], // URL validation // HREFLANG FIELD 'alternate_links' => ['nullable', 'json'], ]); // Clean up the page_path before saving $validated['page_path'] = '/' . ltrim($validated['page_path'], '/'); $meta->update($validated); return redirect()->route('meta.index') ->with('success', 'Meta record updated successfully for ' . $validated['page_path'] . '.'); } /** * Remove the specified meta record from the database. */ public function destroy(Meta $meta) { $path = $meta->page_path; $meta->delete(); return redirect()->route('meta.index') ->with('success', 'Meta record for ' . $path . ' deleted successfully.'); } // ========================================================= // UTILITY FUNCTION FOR FRONTEND // ========================================================= /** * API/Utility function to fetch meta data by path (useful for AJAX or API consumption). * * @param string $path The page path/slug (e.g., 'rooms/suite-a'). Defaults to homepage '/'. */ public function getMetaByPath(string $path = '/') { // Add leading slash if missing (unless it's already the root '/') $cleanPath = ($path !== '/' && !str_starts_with($path, '/')) ? '/' . $path : $path; $meta = Meta::where('page_path', $cleanPath)->first(); if ($meta) { // Returns the data as a JSON response return response()->json($meta); } return response()->json(['message' => 'Meta data not found'], 404); } public function show(Request $request) { // Example: /rooms, /contact-us $path = '/' . ltrim($request->query('path', '/'), '/'); $meta = Meta::where('page_path', $path)->first(); return response()->json($meta); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.2 |
proxy
|
phpinfo
|
Settings