|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Models\Table;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class TableController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* SHow a form for creating a new table
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
$exampleColumns =
|
|
|
|
"latin, string, Latin Name\n".
|
|
|
|
"common, string, Common Name\n".
|
|
|
|
"lifespan, int, Lifespan (years)";
|
|
|
|
|
|
|
|
$exampleData =
|
|
|
|
"Mercenaria mercenaria, hard clam, 40\n" .
|
|
|
|
"Magallana gigas, pacific oyster, 30\n" .
|
|
|
|
"Patella vulgata, common limpet, 20";
|
|
|
|
|
|
|
|
return view('table.create',
|
|
|
|
compact('exampleColumns', 'exampleData')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function storeNew(Request $request)
|
|
|
|
{
|
|
|
|
$u = \Auth::user();
|
|
|
|
|
|
|
|
$this->validate($request, [
|
|
|
|
'name' => 'required',
|
|
|
|
'title' => 'string|nullable',
|
|
|
|
'description' => 'string|nullable',
|
|
|
|
'license' => 'string|nullable',
|
|
|
|
'upstream' => 'string|nullable',
|
|
|
|
'columns' => 'required',
|
|
|
|
'data' => 'string|nullable',
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Check if table name is unique for user
|
|
|
|
$name = $request->get('name');
|
|
|
|
if ($u->tables()->where('name', $name)->exists()) {
|
|
|
|
return $this->backWithErrors([
|
|
|
|
'name' => "A table called \"$name\" already exists in your account.",
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse and validate the columns specification
|
|
|
|
|
|
|
|
// Now we create rows, a revision pointing to them, and the table using it.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return "Ok.";
|
|
|
|
}
|
|
|
|
}
|